java.lang.Object
com.intellij.util.text.CharSequenceSubSequence
- All Implemented Interfaces:
CharSequenceWithStringHash,CharArrayExternalizable,CharSequence
public class CharSequenceSubSequence
extends Object
implements CharSequence, CharArrayExternalizable, CharSequenceWithStringHash
CharSequenceSubSequence allows to save time and memory in text processing code. It avoids
creation of a new char array on every subSequence(int, int) call in contrast to String.subSequence(int, int),
which actually creates a new String instance every time it's invoked.
The downside of using CharSequenceSubSequence is that it keeps reference to the original sequence, which may be large.
Therefore, results of text processing should always be stored as String, to allow garbage collection of the original sequence.
CharSequenceSubSequence implements `hashCode` and `equals` in such a way that it can be compared against String map keys
and set elements without creating a String instance. However, CharSequenceSubSequence should not be used
as a map key or set element, since it keeps reference to the original sequence and prevents its collection.
-
Constructor Summary
ConstructorsConstructorDescriptionCharSequenceSubSequence(@NotNull CharSequence chars) CharSequenceSubSequence(@NotNull CharSequence chars, int start, int end) -
Method Summary
Modifier and TypeMethodDescriptionfinal charcharAt(int index) booleanvoidgetChars(int start, int end, char @NotNull [] dest, int destPos) Copies own character sub-sequence to the given arrayinthashCode()final intlength()@NotNull CharSequencesubSequence(int start, int end) @NotNull StringtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
CharSequenceSubSequence
-
CharSequenceSubSequence
-
-
Method Details
-
length
public final int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public final char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
getChars
public void getChars(int start, int end, char @NotNull [] dest, int destPos) Description copied from interface:CharArrayExternalizableCopies own character sub-sequence to the given array- Specified by:
getCharsin interfaceCharArrayExternalizable- Parameters:
start- the index where to start taking chars from in this sequenceend- the index where to end taking chars in this sequencedest- the array to put characters intodestPos- the index where to put the characters in the dest array
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCharSequenceWithStringHash- Overrides:
hashCodein classObject
-
equals
-