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 toField
whileFeatureType
is equivalent toClass
. Attribute characterization (discussed below) is similar toAnnotation
.Warning: This class is expected to implement a GeoAPIAttributeType
interface in a future version. When such interface will be available, most references toDefaultAttributeType
in current API will be replaced by references to theAttributeType
interface.Value typeAttributes 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 characterizationAnAttribute
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:Constant values of characteristics are given by their default value. It is still possible for any specific- 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.
Attribute
instance to specify their own value, but simple feature usually don't do that.Immutability and thread safetyInstances of this class are immutable if all properties (GenericName
andInternationalString
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 samedefaultValue
instance may be shared by manyAbstractAttribute
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
-
-
-
-
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
orString
AbstractIdentifiedType.getName()
"definition" InternationalString
orString
AbstractIdentifiedType.getDefinition()
"designation" InternationalString
orString
AbstractIdentifiedType.getDesignation()
"description" InternationalString
orString
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, orInteger.MAX_VALUE
if there is no restriction.defaultValue
- the default value for the attribute, ornull
if none.characterizedBy
- other attribute types that describes this attribute type (can benull
for none). For example if this newDefaultAttributeType
describes a measurement, thencharacterizedBy
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 thisAttributeType
shall have at least this minimum number of elements in itscollection 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 thegetMinimumOccurs()
value. If there is no maximum, then this method returnsInteger.MAX_VALUE
.To be valid, an
Attribute
instance of thisAttributeType
shall have no more than this maximum number of elements in itscollection 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 theString
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.
-
-