Class MultiValuedAttribute<V>

Type Parameters:
V - the type of the attribute values.
All Implemented Interfaces:
Serializable, Cloneable

final class MultiValuedAttribute<V> extends AbstractAttribute<V> implements Cloneable
An instance of an attribute type containing an arbitrary number of values.
Note: in the common case where the attribute type restricts the cardinality to [0 … 1], the SingletonAttribute implementation consumes less memory.

Limitations

  • Multi-threading: MultiValuedAttribute instances are not thread-safe. Synchronization, if needed, shall be done externally by the caller.
  • Serialization: serialized objects of this class are not guaranteed to be compatible with future versions. Serialization should be used only for short term storage or RMI between applications running the same SIS version.
  • Cloning: this class support shallow cloning only: the attribute is cloned, but not the value elements.
Since:
0.5
Version:
0.8
See Also:
  • Field Details

    • serialVersionUID

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

      private CheckedArrayList<V> values
      The attribute values.
  • Constructor Details

    • MultiValuedAttribute

      public MultiValuedAttribute(DefaultAttributeType<V> type)
      Creates a new attribute of the given type initialized to the default value.
      Parameters:
      type - information about the attribute (base Java class, domain of values, etc.).
    • MultiValuedAttribute

      MultiValuedAttribute(DefaultAttributeType<V> type, Object values)
      Creates a new attribute of the given type initialized to the given values. Note that a null value may not be the same as the default value.
      Parameters:
      type - information about the attribute (base Java class, domain of values, etc.).
      values - the initial values, or null for initializing to an empty list.
  • Method Details

    • getValue

      public V getValue()
      Returns the attribute value, or null if none.
      Specified by:
      getValue in class AbstractAttribute<V>
      Returns:
      the attribute value (may be null).
      Throws:
      IllegalStateException - if this attribute contains more than one value.
      See Also:
    • getValues

      public Collection<V> getValues()
      Returns all attribute values, or an empty collection if none. The returned collection is live: changes in the returned collection will be reflected immediately in this Attribute instance, and conversely.
      Overrides:
      getValues in class AbstractAttribute<V>
      Returns:
      the attribute values in a live collection.
    • setValue

      public void setValue(V value)
      Sets the attribute value.
      Specified by:
      setValue in class AbstractAttribute<V>
      Parameters:
      value - the new value, or null for removing all values from this attribute.
      See Also:
    • setValues

      public void setValues(Collection<? extends V> newValues)
      Sets the attribute values. All previous values are replaced by the given collection.
      Overrides:
      setValues in class AbstractAttribute<V>
      Parameters:
      newValues - the new values.
    • clone

      Returns a copy of this attribute. This implementation returns a shallow copy: the attribute values are not cloned.
      Overrides:
      clone in class AbstractAttribute<V>
      Returns:
      a clone of this attribute.
      Throws:
      CloneNotSupportedException - if this attribute cannot be cloned.
    • hashCode

      public int hashCode()
      Returns a hash code value for this attribute.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value.
    • equals

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