|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.util.AttributeSource
public class AttributeSource
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 | |
---|---|
static class |
AttributeSource.AttributeFactory
An AttributeFactory creates instances of AttributeImpl s. |
static class |
AttributeSource.State
This class holds the state of an AttributeSource. |
Constructor Summary | |
---|---|
AttributeSource()
An AttributeSource using the default attribute factory AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY . |
|
AttributeSource(AttributeSource.AttributeFactory factory)
An AttributeSource using the supplied AttributeSource.AttributeFactory for creating new Attribute instances. |
|
AttributeSource(AttributeSource input)
An AttributeSource that uses the same attributes as the supplied one. |
Method Summary | ||
---|---|---|
|
addAttribute(Class<A> attClass)
The caller must pass in a Class<? extends Attribute> value. |
|
void |
addAttributeImpl(AttributeImpl att)
Expert: Adds a custom AttributeImpl instance with one or more Attribute interfaces. |
|
AttributeSource.State |
captureState()
Captures the state of all Attributes. |
|
void |
clearAttributes()
Resets all Attributes in this AttributeSource by calling AttributeImpl.clear() on each Attribute implementation. |
|
AttributeSource |
cloneAttributes()
Performs a clone of all AttributeImpl instances returned in a new
AttributeSource instance. |
|
boolean |
equals(Object obj)
|
|
|
getAttribute(Class<A> attClass)
The caller must pass in a Class<? extends Attribute> value. |
|
Iterator<Class<? extends Attribute>> |
getAttributeClassesIterator()
Returns a new iterator that iterates the attribute classes in the same order they were added in. |
|
AttributeSource.AttributeFactory |
getAttributeFactory()
returns the used AttributeFactory. |
|
Iterator<AttributeImpl> |
getAttributeImplsIterator()
Returns a new iterator that iterates all unique Attribute implementations. |
|
boolean |
hasAttribute(Class<? extends Attribute> attClass)
The caller must pass in a Class<? extends Attribute> value. |
|
boolean |
hasAttributes()
Returns true, iff this AttributeSource has any attributes |
|
int |
hashCode()
|
|
void |
restoreState(AttributeSource.State state)
Restores this state by copying the values of all attribute implementations that this state contains into the attributes implementations of the targetStream. |
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public AttributeSource()
AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY
.
public AttributeSource(AttributeSource input)
public AttributeSource(AttributeSource.AttributeFactory factory)
AttributeSource.AttributeFactory
for creating new Attribute
instances.
Method Detail |
---|
public AttributeSource.AttributeFactory getAttributeFactory()
public Iterator<Class<? extends Attribute>> getAttributeClassesIterator()
public Iterator<AttributeImpl> getAttributeImplsIterator()
getAttributeClassesIterator()
,
if one instance implements more than one Attribute interface.
public void addAttributeImpl(AttributeImpl att)
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(java.lang.Class)
after adding
with this method and cast to your class.
The recommended way to use custom implementations is using an AttributeSource.AttributeFactory
.
public <A extends Attribute> A addAttribute(Class<A> attClass)
public boolean hasAttributes()
public boolean hasAttribute(Class<? extends Attribute> attClass)
public <A extends Attribute> A getAttribute(Class<A> attClass)
IllegalArgumentException
- if this AttributeSource does not contain the
Attribute. It is recommended to always use addAttribute(java.lang.Class)
even in consumers
of TokenStreams, because you cannot know if a specific TokenStream really uses
a specific Attribute. addAttribute(java.lang.Class)
will automatically make the attribute
available. If you want to only use the attribute, if it is available (to optimize
consuming), use hasAttribute(java.lang.Class extends org.apache.lucene.util.Attribute>)
.public void clearAttributes()
AttributeImpl.clear()
on each Attribute implementation.
public AttributeSource.State captureState()
restoreState(org.apache.lucene.util.AttributeSource.State)
to restore the state of this or another AttributeSource.
public void restoreState(AttributeSource.State state)
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 clearAttributes()
on the targetStream.
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
public String toString()
toString
in class Object
public AttributeSource cloneAttributes()
AttributeImpl
instances returned in a new
AttributeSource instance. This method can be used to e.g. create another TokenStream
with exactly the same attributes (using AttributeSource(AttributeSource)
)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |