org.carrot2.util.attribute
Class BindableDescriptor

java.lang.Object
  extended by org.carrot2.util.attribute.BindableDescriptor

public class BindableDescriptor
extends Object

Provides a full description of a Bindable type, including AttributeDescriptors for all attributes defined by the type. Also provides some human-readable metadata for the Bindable type itself. BindableDescriptors are immutable.

BindableDescriptors can be obtained from BindableDescriptorBuilder.buildDescriptor(Object).

See Also:
BindableDescriptorBuilder.buildDescriptor(Object)

Nested Class Summary
static class BindableDescriptor.GroupingMethod
          The supported AttributeDescriptor grouping methods.
 
Field Summary
 Map<String,AttributeDescriptor> attributeDescriptors
          Descriptors without any group assignment.
 Map<Object,Map<String,AttributeDescriptor>> attributeGroups
          Grouped descriptors.
 BindableDescriptor.GroupingMethod groupedBy
          The method by which this BindableDescriptor is grouped.
 BindableMetadata metadata
          Human-readable metadata about this Bindable type.
 String prefix
          Prefix of the Bindable this descriptor refers to, as returned by BindableUtils.getPrefix(Class).
 Class<?> type
          The type this BindableDescriptor refers to.
 
Method Summary
 BindableDescriptor flatten()
          Returns a flattened structure of attribute descriptors.
 HashMap<String,Object> getDefaultValues()
          Returns a map of default values of attributes associated with this bindable.
 BindableDescriptor group(BindableDescriptor.GroupingMethod groupingMethod)
          Returns a grouped structure of attribute descriptors.
 BindableDescriptor not(Class<? extends Annotation>... annotationClasses)
          Preserves descriptors that have none of the specified annotations.
 BindableDescriptor only(Class<? extends Annotation>... annotationClasses)
          Preserves descriptors that have all of the specified annotations.
 BindableDescriptor only(com.google.common.base.Predicate<AttributeDescriptor> predicate)
          Preserves attribute descriptors for which the provided predicate returns true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

groupedBy

public final BindableDescriptor.GroupingMethod groupedBy
The method by which this BindableDescriptor is grouped.


type

public final Class<?> type
The type this BindableDescriptor refers to.


prefix

public final String prefix
Prefix of the Bindable this descriptor refers to, as returned by BindableUtils.getPrefix(Class).


attributeDescriptors

public final Map<String,AttributeDescriptor> attributeDescriptors
Descriptors without any group assignment. Keys in the map correspond to attribute keys as defined in Attribute.key().

See Also:
BindableDescriptor.GroupingMethod

attributeGroups

public final Map<Object,Map<String,AttributeDescriptor>> attributeGroups
Grouped descriptors. By default descriptors come ungrouped BindableDescriptor.GroupingMethod.NONE, to get them grouped, use group(GroupingMethod). The iterator returns values of this map in the natural order of keys. For the exact type of the key of this map, see BindableDescriptor.GroupingMethod.


metadata

public final BindableMetadata metadata
Human-readable metadata about this Bindable type.

Method Detail

only

public BindableDescriptor only(com.google.common.base.Predicate<AttributeDescriptor> predicate)
Preserves attribute descriptors for which the provided predicate returns true. Notice that BindableDescriptors are immutable, so the filtered descriptor set is returned rather than filtering being applied to the receiver.

Parameters:
predicate - predicate to the applied
Returns:
a new BindableDescriptor with the descriptors filtered.

only

public BindableDescriptor only(Class<? extends Annotation>... annotationClasses)
Preserves descriptors that have all of the specified annotations. Notice that BindableDescriptors are immutable, so the filtered descriptor set is returned rather than filtering being applied to the receiver.

Parameters:
annotationClasses - binding time and direction annotation classes to be matched.
Returns:
a new BindableDescriptor with the descriptors filtered.

not

public BindableDescriptor not(Class<? extends Annotation>... annotationClasses)
Preserves descriptors that have none of the specified annotations. Notice that BindableDescriptors are immutable, so the filtered descriptor set is returned rather than filtering being applied to the receiver.

Parameters:
annotationClasses - binding time and direction annotation classes to be matched.
Returns:
a new BindableDescriptor with the descriptors filtered.

flatten

public BindableDescriptor flatten()
Returns a flattened structure of attribute descriptors. After flattening, attributeDescriptors contains descriptors of all attributes and attributeGroups is empty. Notice that BindableDescriptors are immutable, so the flattened descriptor set is returned rather than flattening being applied to the receiver.

Returns:
flattened descriptor

group

public BindableDescriptor group(BindableDescriptor.GroupingMethod groupingMethod)
Returns a grouped structure of attribute descriptors. Notice that BindableDescriptors are immutable, so the grouped descriptor set is returned rather than grouping being applied to the receiver.

Parameters:
groupingMethod - the grouping method to be used
Returns:
grouped descriptors

getDefaultValues

public HashMap<String,Object> getDefaultValues()
Returns a map of default values of attributes associated with this bindable. A shortcut for:
 for (AttributeDescriptor d : only(Input.class).flatten().attributeDescriptors.values())
 {
     if (d.defaultValue != null || d.requiredAttribute)
        values.put(d.key, d.defaultValue);
 }
 



Copyright (c) Dawid Weiss, Stanislaw Osinski