Package org.apache.lucene.util
Class CharsRef
java.lang.Object
org.apache.lucene.util.CharsRef
- All Implemented Interfaces:
CharSequence,Cloneable,Comparable<CharsRef>
Represents char[], as a slice (offset + length) into an existing char[].
The
chars member should never be null; use
EMPTY_CHARS if necessary.-
Field Summary
FieldsModifier and TypeFieldDescriptionchar[]The contents of the CharsRef.static final char[]An empty character array for convenienceintLength of used characters.intOffset of first valid character. -
Constructor Summary
ConstructorsConstructorDescriptionCharsRef()Creates a newCharsRefinitialized an empty array zero-lengthCharsRef(char[] chars, int offset, int length) Creates a newCharsRefinitialized with the given array, offset and lengthCharsRef(int capacity) Creates a newCharsRefinitialized with an array of the given capacityCreates a newCharsRefinitialized with the given Strings character array -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(char[] otherChars, int otherOffset, int otherLength) Appends the given array to this CharsRefcharcharAt(int index) booleancharsEquals(CharsRef other) 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.intSigned int order comparisonvoidcopyChars(char[] otherChars, int otherOffset, int otherLength) Copies the given array into this CharsRef.voidCopies the givenCharsRefreferenced content into this instance.static CharsRefdeepCopyOf(CharsRef other) Creates a new CharsRef that points to a copy of the chars fromotherbooleanstatic Comparator<CharsRef>Deprecated.This comparator is only a transition mechanismvoidgrow(int newLength) Used to grow the reference array.inthashCode()booleanisValid()Performs internal consistency checks.intlength()subSequence(int start, int end) toString()Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
EMPTY_CHARS
public static final char[] EMPTY_CHARSAn empty character array for convenience -
chars
public char[] charsThe contents of the CharsRef. Should never benull. -
offset
public int offsetOffset of first valid character. -
length
public int lengthLength of used characters.
-
-
Constructor Details
-
CharsRef
public CharsRef()Creates a newCharsRefinitialized an empty array zero-length -
CharsRef
public CharsRef(int capacity) Creates a newCharsRefinitialized with an array of the given capacity -
CharsRef
public CharsRef(char[] chars, int offset, int length) Creates a newCharsRefinitialized with the given array, offset and length -
CharsRef
Creates a newCharsRefinitialized with the given Strings character array
-
-
Method Details
-
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. -
hashCode
public int hashCode() -
equals
-
charsEquals
-
compareTo
Signed int order comparison- Specified by:
compareToin interfaceComparable<CharsRef>
-
copyChars
Copies the givenCharsRefreferenced content into this instance.- Parameters:
other- theCharsRefto 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
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
getUTF16SortedAsUTF8Comparator
Deprecated.This comparator is only a transition mechanism -
deepCopyOf
Creates a new CharsRef that points to a copy of the chars fromotherThe 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)
-