Save This Page
Home » lucene-3.0.1-src » org.apache » lucene » util » [javadoc | source]
public class: AttributeSource [javadoc | source]
An AttributeSource contains a list of different AttributeImpl s, and methods to add and get them. There can only be a single instance of an attribute in the same AttributeSource instance. This is ensured by passing in the actual type of the Attribute (Class<Attribute>) to the #addAttribute(Class) , which then checks if an instance of that type is already present. If yes, it returns the instance, otherwise it creates a new instance and returns it.
Nested Class Summary:
abstract public static class  AttributeSource.AttributeFactory  An AttributeFactory creates instances of {@link AttributeImpl}s. 
public static final class  AttributeSource.State  This class holds the state of an AttributeSource. 
 public AttributeSource() 
 public AttributeSource(AttributeSource input) 
    An AttributeSource that uses the same attributes as the supplied one.
 public AttributeSource(AttributeFactory factory) 
Method from org.apache.lucene.util.AttributeSource Summary:
addAttribute,   addAttributeImpl,   captureState,   clearAttributes,   cloneAttributes,   equals,   getAttribute,   getAttributeClassesIterator,   getAttributeFactory,   getAttributeImplsIterator,   hasAttribute,   hasAttributes,   hashCode,   restoreState,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.lucene.util.AttributeSource Detail:
 public A addAttribute(Class<A> attClass) 
    The caller must pass in a Class<? extends Attribute> value. This method first checks if an instance of that class is already in this AttributeSource and returns it. Otherwise a new instance is created, added to this AttributeSource and returned.
 public  void addAttributeImpl(AttributeImpl att) 
    Expert: Adds a custom AttributeImpl instance with one or more Attribute interfaces.

    Please note: It is not guaranteed, that att is added to the AttributeSource, because the provided attributes may already exist. You should always retrieve the wanted attributes using #getAttribute after adding with this method and cast to your class. The recommended way to use custom implementations is using an AttributeFactory .

 public State captureState() 
    Captures the state of all Attributes. The return value can be passed to #restoreState to restore the state of this or another AttributeSource.
 public  void clearAttributes() 
    Resets all Attributes in this AttributeSource by calling AttributeImpl#clear() on each Attribute implementation.
 public AttributeSource cloneAttributes() 
 public boolean equals(Object obj) 
 public A getAttribute(Class<A> attClass) 
    The caller must pass in a Class<? extends Attribute> value. Returns the instance of the passed in Attribute contained in this AttributeSource
 public Iterator<Attribute> getAttributeClassesIterator() 
    Returns a new iterator that iterates the attribute classes in the same order they were added in.
 public AttributeFactory getAttributeFactory() 
    returns the used AttributeFactory.
 public Iterator<AttributeImpl> getAttributeImplsIterator() 
    Returns a new iterator that iterates all unique Attribute implementations. This iterator may contain less entries that #getAttributeClassesIterator , if one instance implements more than one Attribute interface.
 public boolean hasAttribute(Class<Attribute> attClass) 
    The caller must pass in a Class<? extends Attribute> value. Returns true, iff this AttributeSource contains the passed-in Attribute.
 public boolean hasAttributes() 
    Returns true, iff this AttributeSource has any attributes
 public int hashCode() 
 public  void restoreState(State state) 
    Restores this state by copying the values of all attribute implementations that this state contains into the attributes implementations of the targetStream. The targetStream must contain a corresponding instance for each argument contained in this state (e.g. it is not possible to restore the state of an AttributeSource containing a TermAttribute into a AttributeSource using a Token instance as implementation).

    Note that this method does not affect attributes of the targetStream that are not contained in this state. In other words, if for example the targetStream contains an OffsetAttribute, but this state doesn't, then the value of the OffsetAttribute remains unchanged. It might be desirable to reset its value to the default, in which case the caller should first call TokenStream#clearAttributes() on the targetStream.

 public String toString()