Class DefaultAttributeType<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 Implemented Interfaces:
Serializable, Deprecable

public class DefaultAttributeType<V> extends FieldType
Definition of an attribute in a feature type. The name of attribute type is mandatory. The name scope is typically the name of the feature type containing this attribute, but this is not mandatory. The scope could also be defined by the ontology for example.
Note: Compared to the Java language, AttributeType is equivalent to Field while FeatureType is equivalent to Class. Attribute characterization (discussed below) is similar to Annotation.
Warning: This class is expected to implement a GeoAPI AttributeType interface in a future version. When such interface will be available, most references to DefaultAttributeType in current API will be replaced by references to the AttributeType interface.

Value type

Attributes can be used for both spatial and non-spatial properties. Some examples are:
Attribute value type examples
Attribute name Value type
Building shape Geometry
Building owner ResponsibleParty
Horizontal accuracy PositionalAccuracy

Attribute characterization

An Attribute can be characterized by other attributes. For example, an attribute that carries a measurement (e.g. air temperature) may have another attribute that holds the measurement accuracy (e.g. ±0.1°C). The accuracy value is often constant for all instances of that attribute (e.g. for all temperature measurements in the same dataset), but this is not mandatory.
Design note: Such accuracy could be stored as an ordinary, independent, attribute (like another column in a table), but storing accuracy as a characteristic of the measurement attribute instead provides the following advantages:
  • The same characteristic name (e.g. “accuracy”) can be used for different attributes (e.g. “temperature”, “humidity”, etc.) since all characteristics are local to their attribute.
  • A reference to an attribute gives also access to its characteristics. For example, any method expecting an Attribute argument, when given a measurement, can also get its accuracy at the same time.
  • In the common case of a simple feature with characteristics that are constants, declaring them as attribute characteristics allows to specify the constants only once.
Constant values of characteristics are given by their default value. It is still possible for any specific Attribute instance to specify their own value, but simple feature usually don't do that.

Immutability and thread safety

Instances of this class are immutable if all properties (GenericName and InternationalString instances) and all arguments (e.g. defaultValue) given to the constructor are also immutable. Such immutable instances can be shared by many objects and passed between threads without synchronization.

In particular, the getDefaultValue() method does not clone the returned value. This means that the same defaultValue instance may be shared by many AbstractAttribute instances. Consequently, the default value should be immutable for avoiding unexpected behavior.

Since:
0.5
Version:
0.8
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • valueClass

      private final Class<V> valueClass
      The class that describe the type of attribute values.
      See Also:
    • defaultValue

      private final V defaultValue
      The default value for the attribute, or null if none.
      See Also:
    • characteristics

      private transient CharacteristicTypeMap characteristics
      Other attribute types that describes this attribute type, or null if none. This is used for attributes of attribute (e.g. accuracy of a position).
      See Also:
  • Constructor Details

  • Method Details

    • writeObject

      private void writeObject(ObjectOutputStream out) throws IOException
      Invoked on serialization for saving the characteristics field.
      Parameters:
      out - The output stream where to serialize this attribute type.
      Throws:
      IOException - if an I/O error occurred while writing.
    • readObject

      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
      Invoked on deserialization for restoring the characteristics field.
      Parameters:
      in - the input stream from which to deserialize an attribute type.
      Throws:
      IOException - if an I/O error occurred while reading or if the stream contains invalid data.
      ClassNotFoundException - if the class serialized on the stream is not on the classpath.
    • getValueClass

      public final Class<V> getValueClass()
      Returns the type of attribute values.
      Returns:
      the type of attribute values.
    • getMinimumOccurs

      public final int getMinimumOccurs()
      Returns the minimum number of attribute values. The returned value is greater than or equal to zero.

      To be valid, an Attribute instance of this AttributeType shall have at least this minimum number of elements in its collection of values.

      Overrides:
      getMinimumOccurs in class FieldType
      Returns:
      the minimum number of attribute values.
    • getMaximumOccurs

      public final int getMaximumOccurs()
      Returns the maximum number of attribute values. The returned value is greater than or equal to the getMinimumOccurs() value. If there is no maximum, then this method returns Integer.MAX_VALUE.

      To be valid, an Attribute instance of this AttributeType shall have no more than this maximum number of elements in its collection of values.

      Overrides:
      getMaximumOccurs in class FieldType
      Returns:
      the maximum number of attribute values, or Integer.MAX_VALUE if none.
    • getDefaultValue

      public V getDefaultValue()
      Returns the default value for the attribute. This value is used when an attribute is created and no value for it is specified.
      Returns:
      the default value for the attribute, or null if none.
    • characteristics

      public Map<String,DefaultAttributeType<?>> characteristics()
      Other attribute types that describes this attribute type. See "Attribute characterization" in class Javadoc for more information.
      Example: An attribute that carries a measurement (e.g. air temperature) may have another attribute that holds the measurement accuracy. The accuracy is often constant for all measurements in a dataset, but not necessarily. If the accuracy is a constant, then the characteristics default value shall hold that constant.
      The characteristics 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 describes this attribute type, or an empty map if none.
      See Also:
    • newInstance

      public AbstractAttribute<V> newInstance()
      Creates a new attribute instance of this type initialized to the default value.
      Returns:
      a new attribute instance.
      See Also:
    • hashCode

      public int hashCode()
      Returns a hash code value for this attribute type.
      Overrides:
      hashCode in class FieldType
      Returns:
      the hash code for this type.
    • equals

      public boolean equals(Object obj)
      Compares this attribute type with the given object for equality.
      Overrides:
      equals in class FieldType
      Parameters:
      obj - the object to compare with this type.
      Returns:
      true if the given object is equal to this type.
    • toString

      public String toString()
      Returns a string representation of this attribute type. The returned string is for debugging purpose and may change in any future SIS version.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this attribute type for debugging purpose.