- Type Parameters:
V
- the type of attribute values. If the attribute supports multi-occurrences, then this is the type of elements (not the collection type).
- All Superinterfaces:
Property
- All Known Subinterfaces:
DynamicAttribute<V>
An instance of an
AttributeType
containing the value of an attribute in a feature.
Attribute
holds three main information:
- A reference to an attribute type which defines the base Java type and domain of valid values.
- One or more values, which may be a singleton ([0 … 1] multiplicity) or multi-valued ([0 … ∞] multiplicity).
- Optional characteristics about the attribute (e.g. a temperature attribute may have a characteristic holding the measurement accuracy). Characteristics are often, but not necessarily, constant for all attributes of the same type in a dataset.
Analogy with Java language:
an attribute is similar to a "field" in a Java object. A field also brings together a field name, value and type,
optionally completed by annotations. The value types are typically
String
, Number
or collections
of them, but other Java type are allowed except Feature
.
For storing a Feature
value, use FeatureAssociation
instead.
Attribute
can be instantiated by calls to AttributeType.newInstance()
.
- Since:
- 3.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionOther attributes that describe this attribute.getName()
Returns the name of this attribute as defined by its type.getType()
Returns information about the attribute (base Java class, domain of values, etc.).getValue()
Returns the attribute value, ornull
if none.Returns all attribute values, or an empty collection if none.void
Sets the attribute value.void
setValues
(Collection<? extends V> values) Sets the attribute values.
-
Method Details
-
getName
Returns the name of this attribute as defined by its type. This convenience method delegates toAttributeType.getName()
. -
getType
Returns information about the attribute (base Java class, domain of values, etc.).- Returns:
- information about the attribute.
-
getValue
Returns the attribute value, ornull
if none. This convenience method can be invoked in the common case where the maximum number of attribute values is restricted to 1 or 0.- Specified by:
getValue
in interfaceProperty
- Returns:
- the attribute value (may be
null
). - Throws:
MultiValuedPropertyException
- if this attribute contains more than one value.- See Also:
-
setValue
Sets the attribute value. All previous values are replaced by the given singleton.Note on validation
The verifications performed by this method is implementation dependent. For performance reasons, an implementation may verify only the most basic constraints and offer another method for performing more extensive validation. Implementations should document their validation process.- Parameters:
value
- the new value, ornull
for removing all values from this attribute.- Throws:
InvalidPropertyValueException
- if this method verifies argument validity and the given value does not met the attribute constraints.- See Also:
-
getValues
Collection<V> getValues()Returns all attribute values, or an empty collection if none. This method supports arbitrary cardinality of attribute values. In the common case where the maximum number of occurrences is restricted to 1,getValue()
is a convenient alternative.Note for implementers
There is different approaches in the way that collection elements are related to this property values:- The collection may be a snapshot of property values at the method invocation time.
- The collection may be an unmodifiable view of properties values.
- The collection may be live (changes in the collection are reflected in this attribute, and vis-versa).
- Returns:
- the attribute values.
-
setValues
Sets the attribute values. All previous values are replaced by the given collection.Note on validation
The verifications performed by this method is implementation dependent. For performance reasons, an implementation may verify only the most basic constraints and offer another method for performing more extensive validation. Implementations should document their validation process.- Parameters:
values
- the new values.- Throws:
InvalidPropertyValueException
- if this method verifies argument validity and the given values do not met the attribute constraints.
-
characteristics
Map<String,Attribute<?>> characteristics()Other attributes that describe this attribute. For example if this attribute carries a measurement, then a characteristic of this attribute could be the measurement accuracy. See Attribute characterization inAttributeType
Javadoc for more information.Attributes having a value equals to their default value do not need to appear in this characteristics map. For example all temperature measurements in a dataset may have the same accuracy, which can be specified only once in the
AttributeType.characteristics()
map instead of being repeated in everyAttribute.characteristics()
maps.The characteristic values are enumerated in the map values. The map keys are the
String
representations of characteristics name, for more convenient lookups.- Returns:
- other attribute types that describe this attribute type, or an empty map if none.
- See Also:
-