Package org.apache.sis.feature
Class SparseFeature
java.lang.Object
org.apache.sis.feature.AbstractFeature
org.apache.sis.feature.SparseFeature
- All Implemented Interfaces:
Serializable
,Cloneable
A feature in which only a small fraction of properties are expected to be provided. This implementation uses
a
Map
for its internal storage of properties. This consumes less memory than a plain array when we
know that the array may be long and likely to be full of null
values.- Since:
- 0.5
- Version:
- 1.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte
AvaluesKind
flag meaning that theproperties
map is invalid.The map of property names to keys in theproperties
map.The properties (attributes or feature associations) in this feature.private static final byte
private static final long
For cross-version compatibility.private static final byte
AvaluesKind
flag meaning that theproperties
map contains raw values.private byte
PROPERTIES
if the values in theproperties
map areProperty
instances, orVALUES
if the map contains only the "raw" property values.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 Integer
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.private Property
getPropertyInstance
(String name) Implementation ofgetProperty(String)
invoked when we know that theproperties
map containsProperty
instances (as opposed to their value).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.private String
Returns the property name at the given index.org.opengis.metadata.quality.DataQuality
quality()
Verifies if all current properties met the constraints defined by the feature type.private void
Sets a value in theproperties
map.private void
Ensures that theproperties
map containsProperty
instances instead of property values.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.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:
-
VALUES
private static final byte VALUESAvaluesKind
flag meaning that theproperties
map contains raw values.- See Also:
-
PROPERTIES
private static final byte PROPERTIES- See Also:
-
CORRUPTED
private static final byte CORRUPTEDAvaluesKind
flag meaning that theproperties
map is invalid.- See Also:
-
indices
The map of property names to keys in theproperties
map. This map is a reference to theDefaultFeatureType.indices
map (potentially shared by many feature instances) and shall not be modified.We use those indices as
properties
keys instead of using directly the property names in order to resolve aliases. -
properties
The properties (attributes or feature associations) in this feature. Conceptually, values in this map areProperty
instances. However, at first we will store only the property values, and build the fullProperty
objects only if they are 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.- See Also:
-
valuesKind
private byte valuesKindPROPERTIES
if the values in theproperties
map areProperty
instances, orVALUES
if the map contains only the "raw" property values.This field is initially
VALUES
, and will be set toPROPERTIES
only if at least oneProperty
instance has been requested. In such case, all property values will have been wrapped into their appropriateProperty
instance.
-
-
Constructor Details
-
SparseFeature
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.
-
nameOf
Returns the property name at the given index. Current implementation is inefficient, but this method should rarely be invoked. -
requireMapOfProperties
private void requireMapOfProperties()Ensures that theproperties
map containsProperty
instances instead of property values. The conversion, if needed, will be performed at most once per 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:
-
getPropertyInstance
Implementation ofgetProperty(String)
invoked when we know that theproperties
map containsProperty
instances (as opposed to their value).- Throws:
IllegalArgumentException
-
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 for another reason.- See Also:
-
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:
-
replace
Sets a value in theproperties
map.- Parameters:
index
- the key of the property to set.oldValue
- the old value, used for verification purpose.newValue
- the new value.
-
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
map is (conceptually) promoted from theMap<Integer,Object>
type to theMap<Integer,Property>
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.
-