Class SparseFeature

java.lang.Object
org.apache.sis.feature.AbstractFeature
org.apache.sis.feature.SparseFeature
All Implemented Interfaces:
Serializable, Cloneable

final class SparseFeature extends AbstractFeature implements 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 Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • VALUES

      private static final byte VALUES
      A valuesKind flag meaning that the properties map contains raw values.
      See Also:
    • PROPERTIES

      private static final byte PROPERTIES
      A valuesKind flag meaning that the properties map contains Property instances.
      See Also:
    • CORRUPTED

      private static final byte CORRUPTED
      A valuesKind flag meaning that the properties map is invalid.
      See Also:
    • indices

      private final Map<String,Integer> indices
      The map of property names to keys in the properties map. This map is a reference to the DefaultFeatureType.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

      private HashMap<Integer,Object> properties
      The properties (attributes or feature associations) in this feature. Conceptually, values in this map are Property instances. However, at first we will store only the property values, and build the full Property 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 valuesKind
      PROPERTIES if the values in the properties map are Property instances, or VALUES if the map contains only the "raw" property values.

      This field is initially VALUES, and will be set to PROPERTIES only if at least one Property instance has been requested. In such case, all property values will have been wrapped into their appropriate Property instance.

  • Constructor Details

    • SparseFeature

      public SparseFeature(DefaultFeatureType type)
      Creates a new feature of the given type.
      Parameters:
      type - information about the feature (name, characteristics, etc.).
  • Method Details

    • getIndex

      private Integer getIndex(String name) throws IllegalArgumentException
      Returns the index for the property of the given name, or DefaultFeatureType.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

      private String nameOf(Integer index)
      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 the properties map contains Property instances instead of property values. The conversion, if needed, will be performed at most once per feature.
    • getProperty

      public Object getProperty(String name) throws IllegalArgumentException
      Returns the property (attribute, operation or association) of the given name.
      Overrides:
      getProperty in class AbstractFeature
      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

      private Property getPropertyInstance(String name) throws IllegalArgumentException
      Implementation of getProperty(String) invoked when we know that the properties map contains Property instances (as opposed to their value).
      Throws:
      IllegalArgumentException
    • setProperty

      public void setProperty(Object property) throws IllegalArgumentException
      Sets the property (attribute, operation or association).
      Overrides:
      setProperty in class AbstractFeature
      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

      public Object getPropertyValue(String name) throws IllegalArgumentException
      Returns the value for the property of the given name.
      Specified by:
      getPropertyValue in class AbstractFeature
      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

      public 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.
      Specified by:
      getValueOrFallback in class AbstractFeature
      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

      public void setPropertyValue(String name, Object value) throws IllegalArgumentException
      Sets the value for the property of the given name.
      Specified by:
      setPropertyValue in class AbstractFeature
      Parameters:
      name - the attribute name.
      value - the new value for the given attribute (may be null).
      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

      private void replace(Integer index, Object oldValue, Object newValue)
      Sets a value in the properties 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 class AbstractFeature
      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 the clone() method of properties.
      Overrides:
      clone in class Object
      Returns:
      a clone of this attribute.
      Throws:
      CloneNotSupportedException - if this feature cannot be cloned, typically because clone() 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 the Property instances, in order to keep the hash code value stable before and after the properties map is (conceptually) promoted from the Map<Integer,Object> type to the Map<Integer,Property> type.
      Overrides:
      hashCode in class AbstractFeature
      Returns:
      a hash code value.
    • equals

      public boolean equals(Object obj)
      Compares this feature with the given object for equality.
      Overrides:
      equals in class AbstractFeature
      Returns:
      true if both objects are equal.