Class AttributeSource

An AttributeSource contains a list of different AttributeImpls,
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.

This method returns the current attribute values as a string in the following format
by calling the reflectWith(AttributeReflector) method:
iff prependAttClass=true:"AttributeClass#key=value,AttributeClass#key=value"iff prependAttClass=false:"key=value,key=value"

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.

addAttributeImpl

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(java.lang.Class<A>) after adding
with this method and cast to your class.
The recommended way to use custom implementations is using an AttributeSource.AttributeFactory.

addAttribute

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.

restoreState

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 clearAttributes() on the targetStream.

cloneAttributes

Performs a clone of all 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)).
You can also use it as a (non-performant) replacement for captureState(), if you need to look
into / modify the captured state.