Package org.apache.sis.feature

## Class DefaultAttributeType<V>

- Object
- - AbstractIdentifiedType
  - - DefaultAttributeType<V>

- Type Parameters:
    `V` - the type of attribute values.
  All Implemented Interfaces:
    `Serializable`, `Deprecable`

      public class DefaultAttributeType<V>
      extends AbstractIdentifiedType

  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 an other 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 in 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
  See Also:
    `DefaultFeatureType`, `AbstractAttribute`, Serialized Form

  Defined in the `sis-feature` module

- - ### Field Summary

    - ### Fields inherited from class AbstractIdentifiedType

      `DEFINITION_KEY, DEPRECATED_KEY, DESCRIPTION_KEY, DESIGNATION_KEY, NAME_KEY`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultAttributeType​(Map<String,​?> identification, Class<V> valueClass, int minimumOccurs, int maximumOccurs, V defaultValue, DefaultAttributeType<?>... characterizedBy)` | Constructs an attribute type from the given properties.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Map<String,​DefaultAttributeType<?>>` | `characteristics()` | Other attribute types that describes this attribute type.
    `boolean` | `equals​(Object obj)` | Compares this attribute type with the given object for equality.
    `V` | `getDefaultValue()` | Returns the default value for the attribute.
    `int` | `getMaximumOccurs()` | Returns the maximum number of attribute values.
    `int` | `getMinimumOccurs()` | Returns the minimum number of attribute values.
    `Class<V>` | `getValueClass()` | Returns the type of attribute values.
    `int` | `hashCode()` | Returns a hash code value for this attribute type.
    `AbstractAttribute<V>` | `newInstance()` | Creates a new attribute instance of this type initialized to the default value.
    `String` | `toString()` | Returns a string representation of this attribute type.

    - ### Methods inherited from class AbstractIdentifiedType

      `getDefinition, getDescription, getDesignation, getName, getRemarks, isDeprecated`

    - ### Methods inherited from class Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultAttributeType

          public DefaultAttributeType​(Map<String,​?> identification,
                                      Class<V> valueClass,
                                      int minimumOccurs,
                                      int maximumOccurs,
                                      V defaultValue,
                                      DefaultAttributeType<?>... characterizedBy)

      Constructs an attribute type from the given properties. The identification map is given unchanged to the super-class constructor. The following table is a reminder of main (not all) recognized map entries:

      Recognized map entries (non exhaustive list)
      Map key | Value type | Returned by
      --- | --- | ---
      "name" | `GenericName` or `String` | `AbstractIdentifiedType.getName()`
      "definition" | `InternationalString` or `String` | `AbstractIdentifiedType.getDefinition()`
      "designation" | `InternationalString` or `String` | `AbstractIdentifiedType.getDesignation()`
      "description" | `InternationalString` or `String` | `AbstractIdentifiedType.getDescription()`
      "deprecated" | `Boolean` | `AbstractIdentifiedType.isDeprecated()`

      Parameters:
        `identification` - the name and other information to be given to this attribute type.
        `valueClass` - the type of attribute values.
        `minimumOccurs` - the minimum number of occurrences of the attribute within its containing entity.
        `maximumOccurs` - the maximum number of occurrences of the attribute within its containing entity, or `Integer​.MAX_VALUE` if there is no restriction.
        `defaultValue` - the default value for the attribute, or `null` if none.
        `characterizedBy` - other attribute types that describes this attribute type (can be `null` for none). For example if this new `DefaultAttributeType` describes a measurement, then `characterizedBy` could holds the measurement accuracy. See "Attribute characterization" in class Javadoc for more information.
      See Also:
        `AttributeTypeBuilder`

  - ### Method Detail

    - #### 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`.

      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`.

      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:
        `AbstractAttribute​.characteristics()`

    - #### 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:
        `AbstractAttribute​.create(DefaultAttributeType)`

    - #### hashCode

          public int hashCode()

      Returns a hash code value for this attribute type.
      Returns:
        the hash code for this type.

    - #### equals

          public boolean equals​(Object obj)

      Compares this attribute type with the given object for equality.
      Parameters:
        `obj` - the object to compare with this type.
      Returns:
        `true` if the given object is equals 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.