org.apache.lucene.analysis.tokenattributes
Class TermAttributeImpl

java.lang.Object
  extended by org.apache.lucene.util.AttributeImpl
      extended by org.apache.lucene.analysis.tokenattributes.TermAttributeImpl
All Implemented Interfaces:
Serializable, Cloneable, TermAttribute, Attribute

public class TermAttributeImpl
extends AttributeImpl
implements TermAttribute, Cloneable, Serializable

The term text of a Token.

See Also:
Serialized Form

Constructor Summary
TermAttributeImpl()
           
 
Method Summary
 void clear()
          Clears the values in this AttributeImpl and resets it to its default value.
 Object clone()
          Shallow clone.
 void copyTo(AttributeImpl target)
          Copies the values from this Attribute into the passed-in target attribute.
 boolean equals(Object other)
          All values used for computation of AttributeImpl.hashCode() should be checked here for equality.
 int hashCode()
          Subclasses must implement this method and should compute a hashCode similar to this:
 char[] resizeTermBuffer(int newSize)
          Grows the termBuffer to at least size newSize, preserving the existing content.
 void setTermBuffer(char[] buffer, int offset, int length)
          Copies the contents of buffer, starting at offset for length characters, into the termBuffer array.
 void setTermBuffer(String buffer)
          Copies the contents of buffer into the termBuffer array.
 void setTermBuffer(String buffer, int offset, int length)
          Copies the contents of buffer, starting at offset and continuing for length characters, into the termBuffer array.
 void setTermLength(int length)
          Set number of valid characters (length of the term) in the termBuffer array.
 String term()
          Returns the Token's term text.
 char[] termBuffer()
          Returns the internal termBuffer character array which you can then directly alter.
 int termLength()
          Return number of valid characters (length of the term) in the termBuffer array.
 String toString()
          The default implementation of this method accesses all declared fields of this object and prints the values in the following syntax:
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TermAttributeImpl

public TermAttributeImpl()
Method Detail

term

public String term()
Returns the Token's term text. This method has a performance penalty because the text is stored internally in a char[]. If possible, use termBuffer() and termLength() directly instead. If you really need a String, use this method, which is nothing more than a convenience call to new String(token.termBuffer(), 0, token.termLength())

Specified by:
term in interface TermAttribute

setTermBuffer

public void setTermBuffer(char[] buffer,
                          int offset,
                          int length)
Copies the contents of buffer, starting at offset for length characters, into the termBuffer array.

Specified by:
setTermBuffer in interface TermAttribute
Parameters:
buffer - the buffer to copy
offset - the index in the buffer of the first character to copy
length - the number of characters to copy

setTermBuffer

public void setTermBuffer(String buffer)
Copies the contents of buffer into the termBuffer array.

Specified by:
setTermBuffer in interface TermAttribute
Parameters:
buffer - the buffer to copy

setTermBuffer

public void setTermBuffer(String buffer,
                          int offset,
                          int length)
Copies the contents of buffer, starting at offset and continuing for length characters, into the termBuffer array.

Specified by:
setTermBuffer in interface TermAttribute
Parameters:
buffer - the buffer to copy
offset - the index in the buffer of the first character to copy
length - the number of characters to copy

termBuffer

public char[] termBuffer()
Returns the internal termBuffer character array which you can then directly alter. If the array is too small for your token, use resizeTermBuffer(int) to increase it. After altering the buffer be sure to call setTermLength(int) to record the number of valid characters that were placed into the termBuffer.

Specified by:
termBuffer in interface TermAttribute

resizeTermBuffer

public char[] resizeTermBuffer(int newSize)
Grows the termBuffer to at least size newSize, preserving the existing content. Note: If the next operation is to change the contents of the term buffer use setTermBuffer(char[], int, int), setTermBuffer(String), or setTermBuffer(String, int, int) to optimally combine the resize with the setting of the termBuffer.

Specified by:
resizeTermBuffer in interface TermAttribute
Parameters:
newSize - minimum size of the new termBuffer
Returns:
newly created termBuffer with length >= newSize

termLength

public int termLength()
Return number of valid characters (length of the term) in the termBuffer array.

Specified by:
termLength in interface TermAttribute

setTermLength

public void setTermLength(int length)
Set 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, use resizeTermBuffer(int) first.

Specified by:
setTermLength in interface TermAttribute
Parameters:
length - the truncated length

hashCode

public int hashCode()
Description copied from class: AttributeImpl
Subclasses must implement this method and should compute a hashCode similar to this:
   public int hashCode() {
     int code = startOffset;
     code = code * 31 + endOffset;
     return code;
   }
 
see also AttributeImpl.equals(Object)

Specified by:
hashCode in class AttributeImpl

clear

public void clear()
Description copied from class: AttributeImpl
Clears 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:
clear in class AttributeImpl

clone

public Object clone()
Description copied from class: AttributeImpl
Shallow clone. Subclasses must override this if they need to clone any members deeply,

Overrides:
clone in class AttributeImpl

equals

public boolean equals(Object other)
Description copied from class: AttributeImpl
All values used for computation of AttributeImpl.hashCode() should be checked here for equality. see also Object.equals(Object)

Specified by:
equals in class AttributeImpl

toString

public String toString()
Description copied from class: AttributeImpl
The default implementation of this method accesses all declared fields of this object and prints the values in the following syntax:
   public String toString() {
     return "start=" + startOffset + ",end=" + endOffset;
   }
 
This method may be overridden by subclasses.

Overrides:
toString in class AttributeImpl

copyTo

public void copyTo(AttributeImpl target)
Description copied from class: AttributeImpl
Copies the values from this Attribute into the passed-in target attribute. The target implementation must support all the Attributes this implementation supports.

Specified by:
copyTo in class AttributeImpl


Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.