org.carrot2.util.attribute
Class AttributeDescriptor

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

public class AttributeDescriptor
extends Object

Provides a full description of an individual attribute, including its key, type, defaultValue and constraints. Also contains human-readable metadata about the attribute such as title, label or description.

AttributeDescriptors can be obtained from BindableDescriptors, which in turn are built by BindableDescriptorBuilder.buildDescriptor(Object);


Nested Class Summary
static class AttributeDescriptor.AttributeDescriptorToKey
          Transforms AttributeDescriptors into their keys.
 
Field Summary
 List<Annotation> constraints
          Constraints defined for the attribute.
 Object defaultValue
          Default value of the attribute.
 boolean inputAttribute
          True if the attribute is an Input attribute.
 String key
          Type of the attribute as defined by Attribute.key().
 AttributeMetadata metadata
          Human-readable metadata describing the attribute.
 boolean outputAttribute
          True if the attribute is an Output attribute.
 boolean requiredAttribute
          True if the attribute is a Required attribute.
 Class<?> type
          Type of the attribute.
 
Method Summary
<T extends Annotation>
T
getAnnotation(Class<T> annotationClass)
          Returns an annotation specified for the attribute.
 boolean isValid(Object value)
          Returns true if the given value is valid for the attribute described by this descriptor (non-null for Required attributes and fulfilling all other constraints).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

metadata

public final AttributeMetadata metadata
Human-readable metadata describing the attribute.


key

public final String key
Type of the attribute as defined by Attribute.key().


type

public final Class<?> type
Type of the attribute. Primitive types are represented by their corresponding wrapper/ box types.


defaultValue

public final Object defaultValue
Default value of the attribute.


constraints

public final List<Annotation> constraints
Constraints defined for the attribute. If the attribute has no constraints, this list is empty.


inputAttribute

public final boolean inputAttribute
True if the attribute is an Input attribute.


outputAttribute

public final boolean outputAttribute
True if the attribute is an Output attribute.


requiredAttribute

public final boolean requiredAttribute
True if the attribute is a Required attribute.

Method Detail

getAnnotation

public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
Returns an annotation specified for the attribute.

Parameters:
annotationClass - type of annotation to be returned
Returns:
annotation of the attribute or null is annotation of the provided type is not defined for the attribute

isValid

public final boolean isValid(Object value)
Returns true if the given value is valid for the attribute described by this descriptor (non-null for Required attributes and fulfilling all other constraints).


toString

public String toString()
Overrides:
toString in class Object


Copyright (c) Dawid Weiss, Stanislaw Osinski