- 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
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.
AbstractAttribute
can be instantiated by calls to DefaultAttributeType.newInstance()
.
Limitations
- Multi-threading:
AbstractAttribute
instances are not thread-safe. Synchronization, if needed, shall be done externally by the caller. - Serialization: serialized objects of this class are not guaranteed to be compatible with future versions. Serialization should be used only for short term storage or RMI between applications running the same SIS version.
- Cloning: despite providing a public
clone()
method, this base class is not cloneable by default. Subclasses shall implement theCloneable
interface themselves if they choose to support cloning.
- Since:
- 0.5
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new attribute of the given type. -
Method Summary
Modifier and TypeMethodDescriptionOther attributes that describes this attribute.clone()
Returns a copy of this attribute if cloning is supported.static <V> AbstractAttribute
<V> create
(DefaultAttributeType<V> type) Creates a new attribute of the given type initialized to the default value.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.).abstract V
Returns the attribute value, ornull
if none.Returns all attribute values, or an empty collection if none.quality()
Evaluates the quality of this attribute at this method invocation time.abstract void
Sets the attribute value.void
setValues
(Collection<? extends V> values) Sets the attribute values.Returns a string representation of this attribute.
-
Constructor Details
-
AbstractAttribute
Creates a new attribute of the given type.- Parameters:
type
- information about the attribute (base Java class, domain of values, etc.).- See Also:
-
-
Method Details
-
create
Creates a new attribute of the given type initialized to the default value.- Type Parameters:
V
- the type of attribute values.- Parameters:
type
- information about the attribute (base Java class, domain of values, etc.).- Returns:
- the new attribute.
- See Also:
-
getName
Returns the name of this attribute as defined by its type. This convenience method delegates toAbstractIdentifiedType.getName()
.- Returns:
- the attribute name specified by its type.
-
getType
Returns information about the attribute (base Java class, domain of values, etc.).Warning: In a future SIS version, the return type may be changed toorg.opengis.feature.AttributeType
. This change is pending GeoAPI revision.- 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.- Returns:
- the attribute value (may be
null
). - Throws:
IllegalStateException
- if this attribute contains more than one value.- See Also:
-
getValues
Returns all attribute values, or an empty collection if none. The returned collection is live: changes in the returned collection will be reflected immediately in thisAttribute
instance, and conversely.The default implementation returns a collection which will delegate its work to
getValue()
andsetValue(Object)
.- Returns:
- the attribute values in a live collection.
-
setValue
Sets the attribute value. All previous values are replaced by the given singleton.Validation
The amount of validation performed by this method is implementation dependent. Usually, only the most basic constraints are verified. This is so for performance reasons and also because some rules may be temporarily broken while constructing a feature. A more exhaustive verification can be performed by invoking thequality()
method.- Parameters:
value
- the new value, ornull
for removing all values from this attribute.- Throws:
IllegalArgumentException
- if this method verifies argument validity and the given value does not met the attribute constraints.- See Also:
-
setValues
Sets the attribute values. All previous values are replaced by the given collection.The default implementation ensures that the given collection contains at most one element, then delegates to
setValue(Object)
.- Parameters:
values
- the new values.- Throws:
IllegalArgumentException
- if the given collection contains too many elements.
-
characteristics
Other attributes that describes this attribute. For example if this attribute carries a measurement, then a characteristic of this attribute could be the measurement accuracy. See "Attribute characterization" inDefaultAttributeType
Javadoc for more information.The map returned by this method contains only the characteristics explicitly defined for this attribute. If the map contains no characteristic for a given name, a default value may still exist. In such cases, callers may also need to inspect the
DefaultAttributeType.characteristics()
as shown in the Reading a characteristic section below.Rational: Very often, all attributes of a given type in the same dataset have the same characteristics. For example, it is very common that all temperature measurements in a dataset have the same accuracy, and setting a different accuracy for a single measurement is relatively rare. Consequently,characteristics.isEmpty()
is a convenient way to check that an attribute have all the "standard" characteristics and need no special processing.Reading a characteristic
The characteristic values are enumerated in the map values. The map keys are theString
representations of characteristics name, for more convenient lookups.If an attribute is known to be a measurement with a characteristic named "accuracy" of type
Float
, then the accuracy value could be read as below:Float getAccuracy(Attribute<?> measurement) { Attribute<?> accuracy = measurement.characteristics().get("accuracy"); if (accuracy != null) { return (Float) accuracy.getValue(); // Value may be null. } else { return (Float) measurement.getType().characteristics().get("accuracy").getDefaultValue(); // A more sophisticated implementation would probably cache the default value somewhere. } }
Adding a characteristic
A new characteristic can be added in the map in three different ways:- Putting the (name, characteristic) pair explicitly.
If an older characteristic existed for that name, it will be replaced.
Example:
Attribute<?> accuracy = ...; // To be created by the caller. characteristics.put("accuracy", accuracy);
- Adding the new characteristic to the values collection.
The name is inferred automatically from the characteristic type.
If an older characteristic existed for the same name, an
IllegalStateException
will be thrown. Example:Attribute<?> accuracy = ...; // To be created by the caller. characteristics.values().add(accuracy);
- Adding the characteristic name to the key set.
If no characteristic existed for that name, a default one will be created.
Example:
characteristics.keySet().add("accuracy"); // Ensure that an entry will exist for that name. Attribute<?> accuracy = characteristics.get("accuracy"); Features.cast(accuracy, Float.class).setValue(...); // Set new accuracy value here as a float.
- Returns:
- other attribute types that describes this attribute type, or an empty map if none.
- See Also:
- Putting the (name, characteristic) pair explicitly.
If an older characteristic existed for that name, it will be replaced.
Example:
-
quality
Evaluates the quality of this attribute at this method invocation time. The data quality reports may include information about whether the attribute value mets the constraints defined by the attribute type, or any other criterion at implementation choice.The default implementation reports data quality with at least the following information:
-
The scope
level is set to
ScopeCode.ATTRIBUTE
. -
At most one domain consistency
element is added to the reports list (implementations are free to omit that element if they have nothing to report).
If a report is provided, then it will contain at least the following information:
-
The attribute name as the data quality measure identification.
Note: strictly speaking,measureIdentification
identifies the quality measurement, not the “real” measurement itself. However, this implementation uses the same set of identifiers for both for simplicity. -
If the attribute value is not an instance of the expected value class, or if the number of occurrences is not inside the multiplicity range, or if any other constraint is violated, then a conformance result is added for each violation with an explanation set to the error message.
Note: this is a departure from ISO intent, sinceexplanation
should be a statement about what a successful conformance means. This point may be reformulated in a future SIS version.
-
false
.Example
Given an attribute named “population” with [1 … 1] multiplicity, if no value has been assigned to that attribute, then thisquality()
method will return the following data quality report:Data quality ├─Scope │ └─Level………………………………………………… Attribute └─Report ├─Measure identification │ └─Code………………………………………… population ├─Evaluation method type…… Direct internal └─Result ├─Explanation……………………… Missing value for “population” property. └─Pass………………………………………… false
- Returns:
- reports on all constraint violations found.
- See Also:
-
The scope
level is set to
-
toString
Returns a string representation of this attribute. The returned string is for debugging purpose and may change in any future SIS version. The current implementation is like below:Attribute[“temperature” : Float] = {20.3, 17.8, 21.1} └─ characteristics: units=°C, accuracy=0.1
-
clone
Returns a copy of this attribute if cloning is supported. The decision to support cloning or not is left to subclasses. If the subclass does not implement theCloneable
interface, then this method throws aCloneNotSupportedException
. Otherwise the default implementation returns a shallow copy of thisAttribute
: the attribute value and characteristics are not cloned. However, subclasses may choose to do otherwise.- Overrides:
clone
in classObject
- Returns:
- a clone of this attribute.
- Throws:
CloneNotSupportedException
- if this attribute, the value or one of its characteristics cannot be cloned.
-