org.apache.lucene.analysis.tokenattributes

## Class PackedTokenAttributeImpl

- java.lang.Object
- - org.apache.lucene.util.AttributeImpl
  - - org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl
    - - org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl

- All Implemented Interfaces:
    Appendable, CharSequence, Cloneable, CharTermAttribute, OffsetAttribute, PositionIncrementAttribute, PositionLengthAttribute, TermToBytesRefAttribute, TypeAttribute, Attribute
  Direct Known Subclasses:
    Token

      public class PackedTokenAttributeImpl
      extends CharTermAttributeImpl
      implements TypeAttribute, PositionIncrementAttribute, PositionLengthAttribute, OffsetAttribute

  Default implementation of the common attributes used by Lucene:
  - `CharTermAttribute`
  - `TypeAttribute`
  - `PositionIncrementAttribute`
  - `PositionLengthAttribute`
  - `OffsetAttribute`

- - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl

      `builder`

    - ### Fields inherited from interface org.apache.lucene.analysis.tokenattributes.TypeAttribute

      `DEFAULT_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PackedTokenAttributeImpl()` Constructs the attribute implementation.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Resets the attributes
    `PackedTokenAttributeImpl` | `clone()` In most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.
    `void` | `copyTo(AttributeImpl target)` Copies the values from this Attribute into the passed-in target attribute.
    `void` | `end()` Resets the attributes at end
    `int` | `endOffset()` Returns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text.
    `boolean` | `equals(Object obj)`
    `int` | `getPositionIncrement()` Returns the position increment of this Token.
    `int` | `getPositionLength()` Returns the position length of this Token.
    `int` | `hashCode()`
    `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`.
    `void` | `setOffset(int startOffset, int endOffset)` Set the starting and ending offset.
    `void` | `setPositionIncrement(int positionIncrement)` Set the position increment.
    `void` | `setPositionLength(int positionLength)` Set the position length of this Token.
    `void` | `setType(String type)` Set the lexical type.
    `int` | `startOffset()` Returns this Token's starting offset, the position of the first character corresponding to this token in the source text.
    `String` | `type()` Returns this Token's lexical type.

    - ### Methods inherited from class org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl

      `append, append, append, append, append, append, buffer, charAt, copyBuffer, getBytesRef, length, resizeBuffer, setEmpty, setLength, subSequence, toString`

    - ### Methods inherited from class org.apache.lucene.util.AttributeImpl

      `reflectAsString`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.CharSequence

      `chars, codePoints`

- - ### Constructor Detail

    - #### PackedTokenAttributeImpl

          public PackedTokenAttributeImpl()

      Constructs the attribute implementation.

  - ### Method Detail

    - #### setPositionIncrement

          public void setPositionIncrement(int positionIncrement)

      Set the position increment. The default value is one.
      Specified by:
        `setPositionIncrement` in interface `PositionIncrementAttribute`
      Parameters:
        `positionIncrement` - the distance from the prior term
      See Also:
        `PositionIncrementAttribute`

    - #### getPositionIncrement

          public int getPositionIncrement()

      Returns the position increment of this Token.
      Specified by:
        `getPositionIncrement` in interface `PositionIncrementAttribute`
      See Also:
        `PositionIncrementAttribute`

    - #### setPositionLength

          public void setPositionLength(int positionLength)

      Set the position length of this Token.

      The default value is one.

      Specified by:
        `setPositionLength` in interface `PositionLengthAttribute`
      Parameters:
        `positionLength` - how many positions this token spans.
      See Also:
        `PositionLengthAttribute`

    - #### getPositionLength

          public int getPositionLength()

      Returns the position length of this Token.
      Specified by:
        `getPositionLength` in interface `PositionLengthAttribute`
      See Also:
        `PositionLengthAttribute`

    - #### startOffset

          public final int startOffset()

      Returns this Token's starting offset, the position of the first character corresponding to this token in the source text.

      Note that the difference between `OffsetAttribute.endOffset()` and `startOffset()` may not be equal to termText.length(), as the term text may have been altered by a stemmer or some other filter.

      Specified by:
        `startOffset` in interface `OffsetAttribute`
      See Also:
        `OffsetAttribute`

    - #### endOffset

          public final int endOffset()

      Returns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text. The length of the token in the source text is (`endOffset()` - `OffsetAttribute.startOffset()`).
      Specified by:
        `endOffset` in interface `OffsetAttribute`
      See Also:
        `OffsetAttribute`

    - #### setOffset

          public void setOffset(int startOffset,
                                int endOffset)

      Set the starting and ending offset.
      Specified by:
        `setOffset` in interface `OffsetAttribute`
      See Also:
        `OffsetAttribute`

    - #### type

          public final String type()

      Returns this Token's lexical type. Defaults to "word".
      Specified by:
        `type` in interface `TypeAttribute`
      See Also:
        `TypeAttribute`

    - #### setType

          public final void setType(String type)

      Set the lexical type.
      Specified by:
        `setType` in interface `TypeAttribute`
      See Also:
        `TypeAttribute`

    - #### clear

          public void clear()

      Resets the attributes
      Overrides:
        `clear` in class `CharTermAttributeImpl`

    - #### end

          public void end()

      Resets the attributes at end
      Overrides:
        `end` in class `AttributeImpl`

    - #### clone

          public PackedTokenAttributeImpl clone()

      Description copied from class: `AttributeImpl`
      In most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.
      Overrides:
        `clone` in class `CharTermAttributeImpl`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `CharTermAttributeImpl`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `CharTermAttributeImpl`

    - #### 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.
      Overrides:
        `copyTo` in class `CharTermAttributeImpl`

    - #### reflectWith

          public void reflectWith(AttributeReflector reflector)

      Description copied from class: `AttributeImpl`
      This method is for introspection of attributes, it should simply add the key/values this attribute holds to the given `AttributeReflector`.

      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!

      Overrides:
        `reflectWith` in class `CharTermAttributeImpl`
      See Also:
        `AttributeImpl.reflectAsString(boolean)`

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