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 byteAvaluesKindflag meaning that thepropertiesmap is invalid.The map of property names to keys in thepropertiesmap.The properties (attributes or feature associations) in this feature.private static final byteprivate static final longFor cross-version compatibility.private static final byteAvaluesKindflag meaning that thepropertiesmap contains raw values.private bytePROPERTIESif the values in thepropertiesmap arePropertyinstances, orVALUESif 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.booleanCompares this feature with the given object for equality.private IntegerReturns the index for the property of the given name, orDefaultFeatureType.OPERATION_INDEXif the property is a parameterless operation.getProperty(String name) Returns the property (attribute, operation or association) of the given name.private PropertygetPropertyInstance(String name) Implementation ofgetProperty(String)invoked when we know that thepropertiesmap containsPropertyinstances (as opposed to their value).getPropertyValue(String name) Returns the value for the property of the given name.final ObjectgetValueOrFallback(String name, Object missingPropertyFallback) Returns the value for the property of the given name if that property exists, or a fallback value otherwise.inthashCode()Returns a hash code value for this feature.private StringReturns the property name at the given index.org.opengis.metadata.quality.DataQualityquality()Verifies if all current properties met the constraints defined by the feature type.private voidSets a value in thepropertiesmap.private voidEnsures that thepropertiesmap containsPropertyinstances instead of property values.voidsetProperty(Object property) Sets the property (attribute, operation or association).voidsetPropertyValue(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 VALUESAvaluesKindflag meaning that thepropertiesmap contains raw values.- See Also:
-
PROPERTIES
private static final byte PROPERTIES- See Also:
-
CORRUPTED
private static final byte CORRUPTEDAvaluesKindflag meaning that thepropertiesmap is invalid.- See Also:
-
indices
The map of property names to keys in thepropertiesmap. This map is a reference to theDefaultFeatureType.indicesmap (potentially shared by many feature instances) and shall not be modified.We use those indices as
propertieskeys 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 arePropertyinstances. However, at first we will store only the property values, and build the fullPropertyobjects 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 valuesKindPROPERTIESif the values in thepropertiesmap arePropertyinstances, orVALUESif the map contains only the "raw" property values.This field is initially
VALUES, and will be set toPROPERTIESonly if at least onePropertyinstance has been requested. In such case, all property values will have been wrapped into their appropriatePropertyinstance.
-
-
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_INDEXif 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 thepropertiesmap containsPropertyinstances 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:
getPropertyin 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 thepropertiesmap containsPropertyinstances (as opposed to their value).- Throws:
IllegalArgumentException
-
setProperty
Sets the property (attribute, operation or association).- Overrides:
setPropertyin 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:
getPropertyValuein classAbstractFeature- Parameters:
name- the property name.- Returns:
- the value for the given property, or
nullif 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:
getValueOrFallbackin 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
nullif none. - Since:
- 1.1
-
setPropertyValue
Sets the value for the property of the given name.- Specified by:
setPropertyValuein 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 thepropertiesmap.- 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:
qualityin 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:
clonein 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 thePropertyinstances, in order to keep the hash code value stable before and after thepropertiesmap is (conceptually) promoted from theMap<Integer,Object>type to theMap<Integer,Property>type.- Overrides:
hashCodein classAbstractFeature- Returns:
- a hash code value.
-
equals
Compares this feature with the given object for equality.- Overrides:
equalsin classAbstractFeature- Returns:
trueif both objects are equal.
-