Package org.apache.lucene.util
Class CharsRef
- java.lang.Object
-
- org.apache.lucene.util.CharsRef
-
- All Implemented Interfaces:
CharSequence
,Cloneable
,Comparable<CharsRef>
public final class CharsRef extends Object implements Comparable<CharsRef>, CharSequence, Cloneable
Represents char[], as a slice (offset + length) into an existing char[]. Thechars
member should never be null; useEMPTY_CHARS
if necessary.
-
-
Field Summary
Fields Modifier and Type Field Description char[]
chars
The contents of the CharsRef.static char[]
EMPTY_CHARS
An empty character array for convenienceint
length
Length of used characters.int
offset
Offset of first valid character.
-
Constructor Summary
Constructors Constructor Description CharsRef()
Creates a newCharsRef
initialized an empty array zero-lengthCharsRef(char[] chars, int offset, int length)
Creates a newCharsRef
initialized with the given array, offset and lengthCharsRef(int capacity)
Creates a newCharsRef
initialized with an array of the given capacityCharsRef(String string)
Creates a newCharsRef
initialized with the given Strings character array
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
append(char[] otherChars, int otherOffset, int otherLength)
Appends the given array to this CharsRefchar
charAt(int index)
boolean
charsEquals(CharsRef other)
CharsRef
clone()
Returns a shallow clone of this instance (the underlying characters are not copied and will be shared by both the returned object and this object.int
compareTo(CharsRef other)
Signed int order comparisonvoid
copyChars(char[] otherChars, int otherOffset, int otherLength)
Copies the given array into this CharsRef.void
copyChars(CharsRef other)
Copies the givenCharsRef
referenced content into this instance.static CharsRef
deepCopyOf(CharsRef other)
Creates a new CharsRef that points to a copy of the chars fromother
boolean
equals(Object other)
static Comparator<CharsRef>
getUTF16SortedAsUTF8Comparator()
Deprecated.This comparator is only a transition mechanismvoid
grow(int newLength)
Used to grow the reference array.int
hashCode()
boolean
isValid()
Performs internal consistency checks.int
length()
CharSequence
subSequence(int start, int end)
String
toString()
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Constructor Detail
-
CharsRef
public CharsRef()
Creates a newCharsRef
initialized an empty array zero-length
-
CharsRef
public CharsRef(int capacity)
Creates a newCharsRef
initialized with an array of the given capacity
-
CharsRef
public CharsRef(char[] chars, int offset, int length)
Creates a newCharsRef
initialized with the given array, offset and length
-
-
Method Detail
-
clone
public CharsRef clone()
Returns a shallow clone of this instance (the underlying characters are not copied and will be shared by both the returned object and this object.- Overrides:
clone
in classObject
- See Also:
deepCopyOf(org.apache.lucene.util.CharsRef)
-
charsEquals
public boolean charsEquals(CharsRef other)
-
compareTo
public int compareTo(CharsRef other)
Signed int order comparison- Specified by:
compareTo
in interfaceComparable<CharsRef>
-
copyChars
public void copyChars(CharsRef other)
Copies the givenCharsRef
referenced content into this instance.- Parameters:
other
- theCharsRef
to copy
-
grow
public void grow(int newLength)
Used to grow the reference array. In general this should not be used as it does not take the offset into account.
-
copyChars
public void copyChars(char[] otherChars, int otherOffset, int otherLength)
Copies the given array into this CharsRef.
-
append
public void append(char[] otherChars, int otherOffset, int otherLength)
Appends the given array to this CharsRef
-
toString
public String toString()
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
length
public int length()
- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfaceCharSequence
-
subSequence
public CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfaceCharSequence
-
getUTF16SortedAsUTF8Comparator
@Deprecated public static Comparator<CharsRef> getUTF16SortedAsUTF8Comparator()
Deprecated.This comparator is only a transition mechanism
-
deepCopyOf
public static CharsRef deepCopyOf(CharsRef other)
Creates a new CharsRef that points to a copy of the chars fromother
The returned CharsRef will have a length of other.length and an offset of zero.
-
isValid
public boolean isValid()
Performs internal consistency checks. Always returns true (or throws IllegalStateException)
-
-