Class AttributeSource
An AttributeSource contains a list of different Attributes, 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 IAttribute to the AddAttribute<T>(), 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.
Inheritance
Assembly: DistributedLucene.Net.dll
Syntax
public class AttributeSource : object
Constructors
Name | Description |
---|---|
AttributeSource() | An AttributeSource using the default attribute factory DEFAULT_ATTRIBUTE_FACTORY. |
AttributeSource(AttributeSource) | An AttributeSource that uses the same attributes as the supplied one. |
AttributeSource(AttributeSource.AttributeFactory) | An AttributeSource using the supplied AttributeSource.AttributeFactory for creating new IAttribute instances. |
Properties
Name | Description |
---|---|
HasAttributes | Returns |
Methods
Name | Description |
---|---|
AddAttribute<T>() | The caller must pass in an interface type that extends IAttribute. This method first checks if an instance of the corresponding class is already in this AttributeSource and returns it. Otherwise a new instance is created, added to this AttributeSource and returned. |
AddAttributeImpl(Attribute) | Expert: Adds a custom Attribute instance with one or more IAttribute interfaces. Please note: It is not guaranteed, that |
CaptureState() | Captures the state of all Attributes. The return value can be passed to RestoreState(AttributeSource.State) to restore the state of this or another AttributeSource. |
ClearAttributes() | Resets all Attributes in this AttributeSource by calling Clear() on each IAttribute implementation. |
CloneAttributes() | Performs a clone of all Attribute 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. |
CopyTo(AttributeSource) | Copies the contents of this AttributeSource to the given target AttributeSource. The given instance has to provide all IAttributes this instance contains. The actual attribute implementations must be identical in both AttributeSource instances; ideally both AttributeSource instances should use the same AttributeSource.AttributeFactory. You can use this method as a replacement for RestoreState(AttributeSource.State), if you use CloneAttributes() instead of CaptureState(). |
Equals(Object) | |
GetAttribute<T>() | The caller must pass in an interface type that extends IAttribute. Returns the instance of the corresponding Attribute contained in this AttributeSource |
GetAttributeClassesEnumerator() | Returns a new iterator that iterates the attribute classes in the same order they were added in. |
GetAttributeFactory() | Returns the used AttributeSource.AttributeFactory. |
GetAttributeImplsEnumerator() | Returns a new iterator that iterates all unique IAttribute implementations. This iterator may contain less entries than GetAttributeClassesEnumerator(), if one instance implements more than one IAttribute interface. |
GetHashCode() | |
HasAttribute<T>() | The caller must pass in an interface type that extends IAttribute.
Returns |
ReflectAsString(Boolean) | This method returns the current attribute values as a string in the following format by calling the ReflectWith(IAttributeReflector) method:
|
ReflectWith(IAttributeReflector) | This method is for introspection of attributes, it should simply add the key/values this AttributeSource holds to the given IAttributeReflector. This method iterates over all IAttribute implementations and calls the corresponding ReflectWith(IAttributeReflector) method. |
RestoreState(AttributeSource.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 ICharTermAttribute 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 IOffsetAttribute, but this state doesn't, then
the value of the IOffsetAttribute remains unchanged. It might be desirable to
reset its value to the default, in which case the caller should first
call ClearAttributes() ( |
ToString() | Returns a string consisting of the class's simple name, the hex representation of the identity hash code, and the current reflection of all attributes. |