Package org.apache.lucene.util
Class CharsRef
- java.lang.Object
 - 
- org.apache.lucene.util.CharsRef
 
 
- 
- All Implemented Interfaces:
 java.lang.CharSequence,java.lang.Cloneable,java.lang.Comparable<CharsRef>
public final class CharsRef extends java.lang.Object implements java.lang.Comparable<CharsRef>, java.lang.CharSequence, java.lang.Cloneable
Represents char[], as a slice (offset + length) into an existing char[]. Thecharsmember should never be null; useEMPTY_CHARSif necessary. 
- 
- 
Field Summary
Fields Modifier and Type Field Description char[]charsThe contents of the CharsRef.static char[]EMPTY_CHARSAn empty character array for convenienceintlengthLength of used characters.intoffsetOffset of first valid character. 
- 
Constructor Summary
Constructors Constructor Description CharsRef()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 capacityCharsRef(java.lang.String string)Creates a newCharsRefinitialized with the given Strings character array 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidappend(char[] otherChars, int otherOffset, int otherLength)Appends the given array to this CharsRefcharcharAt(int index)booleancharsEquals(CharsRef other)CharsRefclone()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.intcompareTo(CharsRef other)Signed int order comparisonvoidcopyChars(char[] otherChars, int otherOffset, int otherLength)Copies the given array into this CharsRef.voidcopyChars(CharsRef other)Copies the givenCharsRefreferenced content into this instance.static CharsRefdeepCopyOf(CharsRef other)Creates a new CharsRef that points to a copy of the chars fromotherbooleanequals(java.lang.Object other)static java.util.Comparator<CharsRef>getUTF16SortedAsUTF8Comparator()Deprecated.This comparator is only a transition mechanismvoidgrow(int newLength)Used to grow the reference array.inthashCode()booleanisValid()Performs internal consistency checks.intlength()java.lang.CharSequencesubSequence(int start, int end)java.lang.StringtoString() 
 - 
 
- 
- 
Constructor Detail
- 
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
public CharsRef(java.lang.String string)
Creates a newCharsRefinitialized with the given Strings character array 
 - 
 
- 
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. 
- 
hashCode
public int hashCode()
- Overrides:
 hashCodein classjava.lang.Object
 
- 
equals
public boolean equals(java.lang.Object other)
- Overrides:
 equalsin classjava.lang.Object
 
- 
charsEquals
public boolean charsEquals(CharsRef other)
 
- 
compareTo
public int compareTo(CharsRef other)
Signed int order comparison- Specified by:
 compareToin interfacejava.lang.Comparable<CharsRef>
 
- 
copyChars
public void copyChars(CharsRef other)
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
public java.lang.String toString()
- Specified by:
 toStringin interfacejava.lang.CharSequence- Overrides:
 toStringin classjava.lang.Object
 
- 
length
public int length()
- Specified by:
 lengthin interfacejava.lang.CharSequence
 
- 
charAt
public char charAt(int index)
- Specified by:
 charAtin interfacejava.lang.CharSequence
 
- 
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
 subSequencein interfacejava.lang.CharSequence
 
- 
getUTF16SortedAsUTF8Comparator
@Deprecated public static java.util.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 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) 
 - 
 
 -