Class CharTermAttributeImpl

    • Constructor Detail

      • CharTermAttributeImpl

        public CharTermAttributeImpl()
        Initialize this attribute with empty term text
    • Method Detail

      • copyBuffer

        public final void copyBuffer​(char[] buffer,
                                     int offset,
                                     int length)
        Description copied from interface: CharTermAttribute
        Copies the contents of buffer, starting at offset for length characters, into the termBuffer array.
        Specified by:
        copyBuffer in interface CharTermAttribute
        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
      • buffer

        public final char[] buffer()
        Description copied from interface: CharTermAttribute
        Returns the internal termBuffer character array which you can then directly alter. If the array is too small for your token, use CharTermAttribute.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().

        Specified by:
        buffer in interface CharTermAttribute
      • resizeBuffer

        public final char[] resizeBuffer​(int newSize)
        Description copied from interface: CharTermAttribute
        Grows the termBuffer to at least size newSize, preserving the existing content.
        Specified by:
        resizeBuffer in interface CharTermAttribute
        Parameters:
        newSize - minimum size of the new termBuffer
        Returns:
        newly created termBuffer with length >= newSize
      • setLength

        public final CharTermAttribute setLength​(int length)
        Description copied from interface: CharTermAttribute
        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 CharTermAttribute.resizeBuffer(int) first.
        Specified by:
        setLength in interface CharTermAttribute
        Parameters:
        length - the truncated length
      • fillBytesRef

        public int fillBytesRef()
        Description copied from interface: TermToBytesRefAttribute
        Updates the bytes TermToBytesRefAttribute.getBytesRef() to contain this term's final encoding, and returns its hashcode.
        Specified by:
        fillBytesRef in interface TermToBytesRefAttribute
        Returns:
        the hashcode as defined by BytesRef.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().
      • length

        public final int length()
        Specified by:
        length in interface java.lang.CharSequence
      • charAt

        public final char charAt​(int index)
        Specified by:
        charAt in interface java.lang.CharSequence
      • subSequence

        public final java.lang.CharSequence subSequence​(int start,
                                                        int end)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • append

        public final CharTermAttribute append​(java.lang.CharSequence csq,
                                              int start,
                                              int end)
        Specified by:
        append in interface java.lang.Appendable
        Specified by:
        append in interface CharTermAttribute
      • append

        public final CharTermAttribute append​(java.lang.String s)
        Description copied from interface: CharTermAttribute
        Appends the specified String 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.

        Specified by:
        append in interface CharTermAttribute
      • append

        public final CharTermAttribute append​(java.lang.StringBuilder s)
        Description copied from interface: CharTermAttribute
        Appends the specified StringBuilder 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.

        Specified by:
        append in interface CharTermAttribute
      • append

        public final CharTermAttribute append​(CharTermAttribute ta)
        Description copied from interface: CharTermAttribute
        Appends the contents of the other CharTermAttribute 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.

        Specified by:
        append in interface CharTermAttribute
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • 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
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns solely the term text as specified by the 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.

        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
      • 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