Class DenseFeature

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

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

    • serialVersionUID

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

      private final Map<String,Integer> indices
      The map of property names to indices in the properties array. This map is a reference to the DefaultFeatureType.indices map (potentially shared by many feature instances) and shall not be modified.
    • properties

      private Object[] properties
      The properties (attributes or feature associations) in this feature. Conceptually, values in this array are Property instances. However, at first we will store only the property values, and convert to an array of type Property[] 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

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

    • getIndex

      private int 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.
    • 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:
    • 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 or another reason.
      See Also:
    • wrapValuesInProperties

      private void wrapValuesInProperties()
      Wraps values in Property objects for all elements in the properties array. This operation is executed at most once per feature.
    • 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:
    • 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 array is promoted from the Object[] type to the 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.