Interface Attribute<V>

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>

public interface Attribute<V> extends Property
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 Details

    • getName

      GenericName getName()
      Returns the name of this attribute as defined by its type. This convenience method delegates to AttributeType.getName().
      Specified by:
      getName in interface Property
      Returns:
      the attribute name specified by its type.
    • getType

      AttributeType<V> getType()
      Returns information about the attribute (base Java class, domain of values, etc.).
      Returns:
      information about the attribute.
    • getValue

      V getValue() throws MultiValuedPropertyException
      Returns the attribute value, or null 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 interface Property
      Returns:
      the attribute value (may be null).
      Throws:
      MultiValuedPropertyException - if this attribute contains more than one value.
      See Also:
    • setValue

      void setValue(V value) throws InvalidPropertyValueException
      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, or null 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.
      Implementation note: 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).
      This method does not mandate a particular approach. However, implementations should document which policy they choose.
      Returns:
      the attribute values.
    • setValues

      void setValues(Collection<? extends V> values) throws InvalidPropertyValueException
      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" in AttributeType 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 every Attribute.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: