Package org.apache.sis.feature
Class DenseFeature
java.lang.Object
org.apache.sis.feature.AbstractFeature
org.apache.sis.feature.DenseFeature
- All Implemented Interfaces:
Serializable
,Cloneable
A feature in which most properties are expected to be provided. This implementation uses a plain array for
its internal storage of properties. This consumes less memory than
Map
when we know that
all (or almost all) elements in the array will be assigned a value.- Since:
- 0.5
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe map of property names to indices in theproperties
array.private Object[]
The properties (attributes or feature associations) in this feature.private static final long
For cross-version compatibility.Fields inherited from class org.apache.sis.feature.AbstractFeature
MISSING, type
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new feature of the given type. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a copy of this feature.boolean
Compares this feature with the given object for equality.private int
Returns the index for the property of the given name, orDefaultFeatureType.OPERATION_INDEX
if the property is a parameterless operation.getProperty
(String name) Returns the property (attribute, operation or association) of the given name.getPropertyValue
(String name) Returns the value for the property of the given name.final Object
getValueOrFallback
(String name, Object missingPropertyFallback) Returns the value for the property of the given name if that property exists, or a fallback value otherwise.int
hashCode()
Returns a hash code value for this feature.org.opengis.metadata.quality.DataQuality
quality()
Verifies if all current properties met the constraints defined by the feature type.void
setProperty
(Object property) Sets the property (attribute, operation or association).void
setPropertyValue
(String name, Object value) Sets the value for the property of the given name.private void
Wraps values inProperty
objects for all elements in theproperties
array.Methods inherited from class org.apache.sis.feature.AbstractFeature
canSkipVerification, comparisonEnd, comparisonStart, createProperty, createProperty, getAssociationValue, getAttributeValue, getDefaultValue, getName, getOperationResult, getOperationValue, getType, propertyNotFound, setOperationValue, setPropertyValue, toString, unsupportedPropertyType, verifyPropertyType, verifyPropertyValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
indices
The map of property names to indices in theproperties
array. This map is a reference to theDefaultFeatureType.indices
map (potentially shared by many feature instances) and shall not be modified. -
properties
The properties (attributes or feature associations) in this feature. Conceptually, values in this array areProperty
instances. However, at first we will store only the property values, and convert to an array of typeProperty[]
only when at least one property is requested. The intent is to reduce the amount of allocated objects as much as possible, because typical SIS applications may create a very large amount of features.
-
-
Constructor Details
-
DenseFeature
Creates a new feature of the given type.- Parameters:
type
- information about the feature (name, characteristics, etc.).
-
-
Method Details
-
getIndex
Returns the index for the property of the given name, orDefaultFeatureType.OPERATION_INDEX
if the property is a parameterless operation.- Parameters:
name
- the property name.- Returns:
- the index for the property of the given name, or a negative value if the property is a parameterless operation.
- Throws:
IllegalArgumentException
- if the given argument is not a property name of this feature.
-
getProperty
Returns the property (attribute, operation or association) of the given name.- Overrides:
getProperty
in classAbstractFeature
- Parameters:
name
- the property name.- Returns:
- the property of the given name.
- Throws:
IllegalArgumentException
- if the given argument is not a property name of this feature.- See Also:
-
setProperty
Sets the property (attribute, operation or association).- Overrides:
setProperty
in classAbstractFeature
- Parameters:
property
- the property to set.- Throws:
IllegalArgumentException
- if the type of the given property is not one of the types known to this feature, or if the property cannot be set or another reason.- See Also:
-
wrapValuesInProperties
private void wrapValuesInProperties()Wraps values inProperty
objects for all elements in theproperties
array. This operation is executed at most once per feature. -
getPropertyValue
Returns the value for the property of the given name.- Specified by:
getPropertyValue
in classAbstractFeature
- Parameters:
name
- the property name.- Returns:
- the value for the given property, or
null
if none. - Throws:
IllegalArgumentException
- if the given argument is not an attribute or association name of this feature.- See Also:
-
getValueOrFallback
Returns the value for the property of the given name if that property exists, or a fallback value otherwise.- Specified by:
getValueOrFallback
in classAbstractFeature
- Parameters:
name
- the property name.missingPropertyFallback
- the value to return if no attribute or association of the given name exists.- Returns:
- the value for the given property, or
null
if none. - Since:
- 1.1
-
setPropertyValue
Sets the value for the property of the given name.- Specified by:
setPropertyValue
in classAbstractFeature
- Parameters:
name
- the attribute name.value
- the new value for the given attribute (may benull
).- Throws:
ClassCastException
- if the value is not assignable to the expected value class.IllegalArgumentException
- if the given value cannot be assigned for another reason.- See Also:
-
quality
public org.opengis.metadata.quality.DataQuality quality()Verifies if all current properties met the constraints defined by the feature type. This method returns reports for all invalid properties, if any.- Overrides:
quality
in classAbstractFeature
- Returns:
- reports on all constraint violations found.
- See Also:
-
clone
Returns a copy of this feature. This method also clones all cloneable property instances in this feature, but not necessarily property values. Whether the property values are cloned or not (i.e. whether the clone operation is deep or shallow) depends on the behavior of theclone()
method of properties.- Overrides:
clone
in classObject
- Returns:
- a clone of this attribute.
- Throws:
CloneNotSupportedException
- if this feature cannot be cloned, typically becauseclone()
on a property instance failed.
-
hashCode
public int hashCode()Returns a hash code value for this feature. This implementation computes the hash code using only the property values, not theProperty
instances, in order to keep the hash code value stable before and after theproperties
array is promoted from theObject[]
type to theProperty[]
type.- Overrides:
hashCode
in classAbstractFeature
- Returns:
- a hash code value.
-
equals
Compares this feature with the given object for equality.- Overrides:
equals
in classAbstractFeature
- Returns:
true
if both objects are equal.
-