public final class AttributeType extends com.davidbracewell.EnumValue implements AnnotatableType
An Attribute
represents a name and value type. Attributes are crated via the create(String)
or the create(String, Class)
static methods. The value type of an attribute is either defined via the
create
method or via a config parameter using a value type (see ValueType
for information of defining the type).
Attributes that do not have a defined type default to being Strings. An attribute can define a custom codec (AttributeValueCodec
*) for encoding and decoding its value using the codec
property, e.g.
Attribute.NAME.codec=fully.qualified.codec.name
. Note that the Attribute
class only
represents the name and type of an attribute.
Attribute names are normalized so that an Attribute created
with the name partofspeech
and one created with the name PartOfSpeech
are equal (see
DynamicEnum
for normalization information).
When attributes are written to a structured format their type
is checked against what is defined. Differences in type will by default cause ignore the attribute and not write it
to file. You can set Attribute.ignoreTypeChecks
to false
to ensure the type and throw an
IllegalArgumentException
when there is a mismatch.
Modifier and Type | Method and Description |
---|---|
static AttributeType |
create(String name)
Creates an attribute with the given name.
|
static AttributeType |
create(String name,
Class<?> valueType)
Creates a new attribute with the given name and value type
|
com.davidbracewell.reflection.ValueType |
getValueType()
Gets class information for the type of values this attribute is expected to have.
|
static boolean |
isDefined(String name)
Determine if a name is an existing Attribute
|
String |
type()
The type (Annotation, Attribute, Relation)
|
static AttributeType |
valueOf(String name)
Gets the attribute associated with a string.
|
static Collection<AttributeType> |
values()
The current collection of known attributes
|
canEqual, compareTo, equals, hashCode, isInstance, name, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
canonicalName, getAnnotator, name
public static AttributeType create(String name, @NonNull Class<?> valueType)
name
- the name of the attributevalueType
- the type of attribute's valueIllegalArgumentException
- If the name is invalid or an attribute exists with this name, but a differenty
value type.public static AttributeType create(String name)
name
- the name of the attributeIllegalArgumentException
- If the name is invalidpublic static boolean isDefined(String name)
name
- the namepublic static AttributeType valueOf(String name)
name
- the name as a stringIllegalArgumentException
- if the name is not a valid attributepublic static Collection<AttributeType> values()
public String type()
AnnotatableType
type
in interface AnnotatableType
public com.davidbracewell.reflection.ValueType getValueType()
Attribute.NAME.type = class
. If not defined String.class will be returned.Copyright © 2016. All rights reserved.