Class CharTermAttributeImpl
- All Implemented Interfaces:
Appendable,CharSequence,Cloneable,CharTermAttribute,TermToBytesRefAttribute,Attribute
- Direct Known Subclasses:
PackedTokenAttributeImpl
CharTermAttribute.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BytesRefBuilderMay be used by subclasses to convert to different charsets / encodings for implementinggetBytesRef(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal CharTermAttributeappend(char c) final CharTermAttributeappend(CharSequence csq) final CharTermAttributeappend(CharSequence csq, int start, int end) final CharTermAttributeAppends the specifiedStringto this character sequence.final CharTermAttributeAppends the specifiedStringBuilderto this character sequence.final CharTermAttributeAppends the contents of the otherCharTermAttributeto this character sequence.final char[]buffer()Returns the internal termBuffer character array which you can then directly alter.final charcharAt(int index) voidclear()Clears the values in this AttributeImpl and resets it to its default value.clone()In most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.final voidcopyBuffer(char[] buffer, int offset, int length) Copies the contents of buffer, starting at offset for length characters, into the termBuffer array.voidcopyTo(AttributeImpl target) Copies the values from this Attribute into the passed-in target attribute.booleanRetrieve this attribute's BytesRef.inthashCode()final intlength()voidreflectWith(AttributeReflector reflector) This method is for introspection of attributes, it should simply add the key/values this attribute holds to the givenAttributeReflector.final char[]resizeBuffer(int newSize) Grows the termBuffer to at least size newSize, preserving the existing content.final CharTermAttributesetEmpty()Sets the length of the termBuffer to zero.final CharTermAttributesetLength(int length) Set number of valid characters (length of the term) in the termBuffer array.final CharSequencesubSequence(int start, int end) toString()Returns solely the term text as specified by theCharSequenceinterface.Methods inherited from class org.apache.lucene.util.AttributeImpl
end, reflectAsStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
builder
May be used by subclasses to convert to different charsets / encodings for implementinggetBytesRef().
-
-
Constructor Details
-
CharTermAttributeImpl
public CharTermAttributeImpl()Initialize this attribute with empty term text
-
-
Method Details
-
copyBuffer
public final void copyBuffer(char[] buffer, int offset, int length) Description copied from interface:CharTermAttributeCopies the contents of buffer, starting at offset for length characters, into the termBuffer array.- Specified by:
copyBufferin interfaceCharTermAttribute- Parameters:
buffer- the buffer to copyoffset- the index in the buffer of the first character to copylength- the number of characters to copy
-
buffer
public final char[] buffer()Description copied from interface:CharTermAttributeReturns the internal termBuffer character array which you can then directly alter. If the array is too small for your token, useCharTermAttribute.resizeBuffer(int)to increase it. After altering the buffer be sure to callCharTermAttribute.setLength(int)to record the number of valid characters that were placed into the termBuffer.NOTE: The returned buffer may be larger than the valid
CharSequence.length().- Specified by:
bufferin interfaceCharTermAttribute
-
resizeBuffer
public final char[] resizeBuffer(int newSize) Description copied from interface:CharTermAttributeGrows the termBuffer to at least size newSize, preserving the existing content.- Specified by:
resizeBufferin interfaceCharTermAttribute- Parameters:
newSize- minimum size of the new termBuffer- Returns:
- newly created termBuffer with
length >= newSize
-
setLength
Description copied from interface:CharTermAttributeSet number of valid characters (length of the term) in the termBuffer array. Use this to truncate the termBuffer or to synchronize with external manipulation of the termBuffer. Note: to grow the size of the array, useCharTermAttribute.resizeBuffer(int)first.- Specified by:
setLengthin interfaceCharTermAttribute- Parameters:
length- the truncated length
-
setEmpty
Description copied from interface:CharTermAttributeSets the length of the termBuffer to zero. Use this method before appending contents using theAppendableinterface.- Specified by:
setEmptyin interfaceCharTermAttribute
-
getBytesRef
Description copied from interface:TermToBytesRefAttributeRetrieve this attribute's BytesRef. The bytes are updated from the current term. The implementation may return a new instance or keep the previous one.- Specified by:
getBytesRefin interfaceTermToBytesRefAttribute- Returns:
- a BytesRef to be indexed (only stays valid until token stream gets incremented)
-
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
-
append
- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceCharTermAttribute
-
append
- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceCharTermAttribute
-
append
- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceCharTermAttribute
-
append
Description copied from interface:CharTermAttributeAppends the specifiedStringto this character sequence.The characters of the
Stringargument are appended, in order, increasing the length of this sequence by the length of the argument. If argument isnull, then the four characters"null"are appended.- Specified by:
appendin interfaceCharTermAttribute
-
append
Description copied from interface:CharTermAttributeAppends the specifiedStringBuilderto this character sequence.The characters of the
StringBuilderargument are appended, in order, increasing the length of this sequence by the length of the argument. If argument isnull, then the four characters"null"are appended.- Specified by:
appendin interfaceCharTermAttribute
-
append
Description copied from interface:CharTermAttributeAppends the contents of the otherCharTermAttributeto this character sequence.The characters of the
CharTermAttributeargument are appended, in order, increasing the length of this sequence by the length of the argument. If argument isnull, then the four characters"null"are appended.- Specified by:
appendin interfaceCharTermAttribute
-
hashCode
public int hashCode() -
clear
public void clear()Description copied from class:AttributeImplClears the values in this AttributeImpl and resets it to its default value. If this implementation implements more than one Attribute interface it clears all.- Specified by:
clearin classAttributeImpl
-
clone
Description copied from class:AttributeImplIn most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.- Overrides:
clonein classAttributeImpl
-
equals
-
toString
Returns solely the term text as specified by theCharSequenceinterface.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
reflectWith
Description copied from class:AttributeImplThis method is for introspection of attributes, it should simply add the key/values this attribute holds to the givenAttributeReflector.Implementations look like this (e.g. for a combined attribute implementation):
public void reflectWith(AttributeReflector reflector) { reflector.reflect(CharTermAttribute.class, "term", term()); reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", getPositionIncrement()); }If you implement this method, make sure that for each invocation, the same set of
Attributeinterfaces and keys are passed toAttributeReflector.reflect(java.lang.Class<? extends org.apache.lucene.util.Attribute>, java.lang.String, java.lang.Object)in the same order, but possibly different values. So don't automatically exclude e.g.nullproperties!- Specified by:
reflectWithin classAttributeImpl- See Also:
-
copyTo
Description copied from class:AttributeImplCopies the values from this Attribute into the passed-in target attribute. The target implementation must support all the Attributes this implementation supports.- Specified by:
copyToin classAttributeImpl
-