V
- The type of attribute values.public abstract class AbstractAttribute<V> extends Object implements Cloneable, Serializable
Attribute
holds three main information:
AbstractAttribute
can be instantiated by calls to DefaultAttributeType.newInstance()
.
AbstractAttribute
instances are not thread-safe.
Synchronization, if needed, shall be done externally by the caller.DefaultAttributeType.newInstance()
,
Serialized FormDefined in the sis-feature
module
Modifier | Constructor and Description |
---|---|
protected |
AbstractAttribute(DefaultAttributeType<V> type)
Creates a new attribute of the given type.
|
Modifier and Type | Method and Description |
---|---|
Map<String,AbstractAttribute<?>> |
characteristics()
Other attributes that describes this attribute.
|
AbstractAttribute<V> |
clone()
Returns a copy of this attribute.
|
static <V> AbstractAttribute<V> |
create(DefaultAttributeType<V> type)
Creates a new attribute of the given type initialized to the
default value.
|
GenericName |
getName()
Returns the name of this attribute as defined by its type.
|
DefaultAttributeType<V> |
getType()
Returns information about the attribute (base Java class, domain of values, etc.
|
abstract V |
getValue()
Returns the attribute value, or
null if none. |
Collection<V> |
getValues()
Returns all attribute values, or an empty collection if none.
|
DataQuality |
quality()
Evaluates the quality of this attribute at this method invocation time.
|
abstract void |
setValue(V value)
Sets the attribute value.
|
void |
setValues(Collection<? extends V> values)
Sets the attribute values.
|
String |
toString()
Returns a string representation of this attribute.
|
protected AbstractAttribute(DefaultAttributeType<V> type)
type
- Information about the attribute (base Java class, domain of values, etc.).create(DefaultAttributeType)
public static <V> AbstractAttribute<V> create(DefaultAttributeType<V> type)
V
- The type of attribute values.type
- Information about the attribute (base Java class, domain of values, etc.).DefaultAttributeType.newInstance()
public GenericName getName()
AbstractIdentifiedType.getName()
.public DefaultAttributeType<V> getType()
org.opengis.feature.AttributeType
. This change is pending GeoAPI revision.public abstract V getValue() throws IllegalStateException
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.null
).IllegalStateException
- if this attribute contains more than one value.AbstractFeature.getPropertyValue(String)
public Collection<V> getValues()
Attribute
instance, and conversely.
The default implementation returns a collection which will delegate its work to
getValue()
and setValue(Object)
.
public abstract void setValue(V value)
quality()
method.value
- The new value, or null
for removing all values from this attribute.AbstractFeature.setPropertyValue(String, Object)
public void setValues(Collection<? extends V> values) throws IllegalArgumentException
The default implementation ensures that the given collection contains at most one element,
then delegates to setValue(Object)
.
values
- The new values.IllegalArgumentException
- if the given collection contains too many elements.public Map<String,AbstractAttribute<?>> characteristics()
DefaultAttributeType
Javadoc for more information.
The map returned by this method contains only the characteristics explicitely 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.
characteristics.isEmpty()
is a convenient way to check that an attribute have
all the "standard" characteristics and need no special processing.String
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. } }
Attribute<?> accuracy = ...; // To be created by the caller. characteristics.put("accuracy", accuracy);
IllegalStateException
will be thrown.
Example:
Attribute<?> accuracy = ...; // To be created by the caller. characteristics.values().add(accuracy);
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.
DefaultAttributeType.characteristics()
public DataQuality quality()
The default implementation reports data quality with at least the following information:
ScopeCode.ATTRIBUTE
.
The attribute name as the data quality measure identification.
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 cardinality 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.
explanation
should be a statement about what a successful conformance means. This point may be reformulated
in a future SIS version.false
.
quality()
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
AbstractFeature.quality()
@Debug public String toString()
Attribute[“temperature” : Float] = {20.3, 17.8, 21.1} └─ characteristics: units=°C, accuracy=0.1
public AbstractAttribute<V> clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- if this attribute, the value
or one of its characteristics can not be cloned.Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.