public class CharTermAttributeImpl extends AttributeImpl implements CharTermAttribute, TermToBytesRefAttribute, Cloneable
CharTermAttribute.| Constructor and Description |
|---|
CharTermAttributeImpl()
Initialize this attribute with empty term text
|
| Modifier and Type | Method and Description |
|---|---|
CharTermAttribute |
append(char c) |
CharTermAttribute |
append(CharSequence csq) |
CharTermAttribute |
append(CharSequence csq,
int start,
int end) |
CharTermAttribute |
append(CharTermAttribute ta)
Appends the contents of the other
CharTermAttribute to this character sequence. |
CharTermAttribute |
append(String s)
Appends the specified
String to this character sequence. |
CharTermAttribute |
append(StringBuilder s)
Appends the specified
StringBuilder to this character sequence. |
char[] |
buffer()
Returns the internal termBuffer character array which
you can then directly alter.
|
char |
charAt(int index) |
void |
clear()
Clears the values in this AttributeImpl and resets it to its
default value.
|
CharTermAttributeImpl |
clone()
Shallow clone.
|
void |
copyBuffer(char[] buffer,
int offset,
int length)
Copies the contents of buffer, starting at offset for
length characters, into the termBuffer array.
|
void |
copyTo(AttributeImpl target)
Copies the values from this Attribute into the passed-in
target attribute.
|
boolean |
equals(Object other) |
int |
fillBytesRef()
Updates the bytes
TermToBytesRefAttribute.getBytesRef() to contain this term's
final encoding, and returns its hashcode. |
BytesRef |
getBytesRef()
Retrieve this attribute's BytesRef.
|
int |
hashCode() |
int |
length() |
void |
reflectWith(AttributeReflector reflector)
This method is for introspection of attributes, it should simply
add the key/values this attribute holds to the given
AttributeReflector. |
char[] |
resizeBuffer(int newSize)
Grows the termBuffer to at least size newSize, preserving the
existing content.
|
CharTermAttribute |
setEmpty()
Sets the length of the termBuffer to zero.
|
CharTermAttribute |
setLength(int length)
Set number of valid characters (length of the term) in
the termBuffer array.
|
CharSequence |
subSequence(int start,
int end) |
String |
toString()
Returns solely the term text as specified by the
CharSequence interface. |
reflectAsStringpublic CharTermAttributeImpl()
public final void copyBuffer(char[] buffer,
int offset,
int length)
CharTermAttributecopyBuffer in interface CharTermAttributebuffer - the buffer to copyoffset - the index in the buffer of the first character to copylength - the number of characters to copypublic final char[] buffer()
CharTermAttributeCharTermAttribute.resizeBuffer(int) to increase it. After
altering the buffer be sure to call CharTermAttribute.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().
buffer in interface CharTermAttributepublic final char[] resizeBuffer(int newSize)
CharTermAttributeresizeBuffer in interface CharTermAttributenewSize - minimum size of the new termBufferpublic final CharTermAttribute setLength(int length)
CharTermAttributeCharTermAttribute.resizeBuffer(int) first.setLength in interface CharTermAttributelength - the truncated lengthpublic final CharTermAttribute setEmpty()
CharTermAttributeAppendable interface.setEmpty in interface CharTermAttributepublic int fillBytesRef()
TermToBytesRefAttributeTermToBytesRefAttribute.getBytesRef() to contain this term's
final encoding, and returns its hashcode.fillBytesRef in interface TermToBytesRefAttributeBytesRef.hashCode():
int hash = 0;
for (int i = termBytes.offset; i < termBytes.offset+termBytes.length; i++) {
hash = 31*hash + termBytes.bytes[i];
}
Implement this for performance reasons, if your code can calculate
the hash on-the-fly. If this is not the case, just return
termBytes.hashCode().public BytesRef getBytesRef()
TermToBytesRefAttributeTermToBytesRefAttribute.fillBytesRef().getBytesRef in interface TermToBytesRefAttributepublic final int length()
length in interface CharSequencepublic final char charAt(int index)
charAt in interface CharSequencepublic final CharSequence subSequence(int start, int end)
subSequence in interface CharSequencepublic final CharTermAttribute append(CharSequence csq)
append in interface Appendableappend in interface CharTermAttributepublic final CharTermAttribute append(CharSequence csq, int start, int end)
append in interface Appendableappend in interface CharTermAttributepublic final CharTermAttribute append(char c)
append in interface Appendableappend in interface CharTermAttributepublic final CharTermAttribute append(String s)
CharTermAttributeString to this character sequence.
The characters of the String argument are appended, in order, increasing the length of
this sequence by the length of the argument. If argument is null, then the four
characters "null" are appended.
append in interface CharTermAttributepublic final CharTermAttribute append(StringBuilder s)
CharTermAttributeStringBuilder to this character sequence.
The characters of the StringBuilder argument are appended, in order, increasing the length of
this sequence by the length of the argument. If argument is null, then the four
characters "null" are appended.
append in interface CharTermAttributepublic final CharTermAttribute append(CharTermAttribute ta)
CharTermAttributeCharTermAttribute to this character sequence.
The characters of the CharTermAttribute argument are appended, in order, increasing the length of
this sequence by the length of the argument. If argument is null, then the four
characters "null" are appended.
append in interface CharTermAttributepublic void clear()
AttributeImplclear in class AttributeImplpublic CharTermAttributeImpl clone()
AttributeImplclone in class AttributeImplpublic String toString()
CharSequence interface.
This method changed the behavior with Lucene 3.1,
before it returned a String representation of the whole
term with all attributes.
This affects especially the
Token subclass.
toString in interface CharSequencetoString in class Objectpublic void reflectWith(AttributeReflector reflector)
AttributeImplAttributeReflector.
The default implementation calls AttributeReflector.reflect(java.lang.Class<? extends org.apache.lucene.util.Attribute>, java.lang.String, java.lang.Object) for all
non-static fields from the implementing class, using the field name as key
and the field value as value. The Attribute class is also determined by reflection.
Please note that the default implementation can only handle single-Attribute
implementations.
Custom 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 Attribute
interfaces and keys are passed to AttributeReflector.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. null properties!
reflectWith in class AttributeImplAttributeImpl.reflectAsString(boolean)public void copyTo(AttributeImpl target)
AttributeImplcopyTo in class AttributeImplCopyright © 2000-2013 Apache Software Foundation. All Rights Reserved.