Class ParameterValueList

java.lang.Object
java.util.AbstractCollection<org.opengis.parameter.GeneralParameterValue>
java.util.AbstractList<org.opengis.parameter.GeneralParameterValue>
org.apache.sis.parameter.ParameterValueList
All Implemented Interfaces:
Serializable, Iterable<org.opengis.parameter.GeneralParameterValue>, Collection<org.opengis.parameter.GeneralParameterValue>, List<org.opengis.parameter.GeneralParameterValue>, RandomAccess, SequencedCollection<org.opengis.parameter.GeneralParameterValue>

final class ParameterValueList extends AbstractList<org.opengis.parameter.GeneralParameterValue> implements RandomAccess, Serializable
The list to be returned by DefaultParameterValueGroup.values(). This class performs checks on the parameter values to be added or removed. This implementation supports set(…), add(…) and remove(…) operations.
Implementation note: this class reproduces some ArrayList functionalities. However, we do not extend ArrayList because we really need the default method implementations provided by AbstractList — the optimizations performed by ArrayList are not suitable here.
Since:
0.4
Version:
0.4
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial number for inter-operability with different versions.
      See Also:
    • descriptor

      final org.opengis.parameter.ParameterDescriptorGroup descriptor
      The descriptor for the list as a whole.

      This descriptor shall not be used in AbstractList.equals(Object) and AbstractList.hashCode() implementations in order to stay consistent with the List contract.

    • values

      private org.opengis.parameter.GeneralParameterValue[] values
      The parameter values in the group. The length of this array is the list capacity. This array will growth as needed.
    • size

      private int size
      Number of valid elements in the values array.
  • Constructor Details

    • ParameterValueList

      ParameterValueList(org.opengis.parameter.ParameterDescriptorGroup descriptor)
      Constructs an initially empty parameter list.
      Parameters:
      descriptor - the descriptor for this list.
    • ParameterValueList

      ParameterValueList(ParameterValueList other)
      Constructs a parameter list initialized to a copy of the given one.
  • Method Details

    • initialize

      private void initialize(List<org.opengis.parameter.GeneralParameterDescriptor> elements)
      Adds all mandatory parameters to this list. This method can be invoked only after construction or after a call to clear().
    • clear

      public void clear()
      Clears this list, then recreate the mandatory parameters.
      Specified by:
      clear in interface Collection<org.opengis.parameter.GeneralParameterValue>
      Specified by:
      clear in interface List<org.opengis.parameter.GeneralParameterValue>
      Overrides:
      clear in class AbstractList<org.opengis.parameter.GeneralParameterValue>
    • size

      public int size()
      Returns the number of parameters in this list.
      Specified by:
      size in interface Collection<org.opengis.parameter.GeneralParameterValue>
      Specified by:
      size in interface List<org.opengis.parameter.GeneralParameterValue>
      Specified by:
      size in class AbstractCollection<org.opengis.parameter.GeneralParameterValue>
    • descriptor

      final org.opengis.parameter.GeneralParameterDescriptor descriptor(int index)
      Returns the descriptor at the given index. This method is preferable to get(i).getDescriptor() when the caller does not need the replacement of UninitializedParameter instances.
    • get

      public org.opengis.parameter.GeneralParameterValue get(int index)
      Returns the parameter value at the given index. If the parameter at the given index is a mandatory parameter pending creation of the actual value, the value will be created now.
      Specified by:
      get in interface List<org.opengis.parameter.GeneralParameterValue>
      Specified by:
      get in class AbstractList<org.opengis.parameter.GeneralParameterValue>
    • set

      public org.opengis.parameter.GeneralParameterValue set(int index, org.opengis.parameter.GeneralParameterValue parameter)
      Sets the parameter at the given index. The descriptor of the given parameter must be one of those in the DefaultParameterDescriptorGroup.descriptors() list, and storing that parameter must be allowed by the cardinality constraints.
      Specified by:
      set in interface List<org.opengis.parameter.GeneralParameterValue>
      Overrides:
      set in class AbstractList<org.opengis.parameter.GeneralParameterValue>
    • add

      public boolean add(org.opengis.parameter.GeneralParameterValue parameter)
      Adds a ParameterValue or another ParameterValueGroup to this list. If an existing parameter is already included for the same name and adding the new parameter would increase the number past what is allowable by maximumOccurs, then an InvalidParameterCardinalityException will be thrown.
      Specified by:
      add in interface Collection<org.opengis.parameter.GeneralParameterValue>
      Specified by:
      add in interface List<org.opengis.parameter.GeneralParameterValue>
      Overrides:
      add in class AbstractList<org.opengis.parameter.GeneralParameterValue>
      Parameters:
      parameter - new parameter to be added to this group.
      Returns:
      always true since this object changes as a result of this call.
      Throws:
      IllegalArgumentException - if the specified parameter is not allowable by the groups descriptor.
      org.opengis.parameter.InvalidParameterCardinalityException - if adding this parameter would result in more parameters than allowed by maximumOccurs.
    • addUnchecked

      final void addUnchecked(org.opengis.parameter.GeneralParameterValue parameter)
      Unconditionally adds the given parameter to this list without any validity check. The internal array will growth as needed.
    • ensureDescriptorExists

      final void ensureDescriptorExists(org.opengis.parameter.GeneralParameterDescriptor desc)
      Verifies the given descriptor exists in the DefaultParameterDescriptorGroup.descriptors() list.
    • ensureCanAdd

      private void ensureCanAdd(org.opengis.parameter.GeneralParameterDescriptor desc)
      Verifies if adding a parameter with the given descriptor is allowed by the cardinality constraints. If adding the parameter would result in more occurrences than AbstractParameterDescriptor.getMaximumOccurs(), then this method throws an InvalidParameterCardinalityException.
    • ensureCanRemove

      private void ensureCanRemove(org.opengis.parameter.GeneralParameterDescriptor desc)
      Verifies if removing the given value is allowed by the cardinality constraints. If removing the parameter would result in less occurrences than AbstractParameterDescriptor.getMinimumOccurs(), then this method throws an InvalidParameterCardinalityException.
    • remove

      public org.opengis.parameter.GeneralParameterValue remove(int index)
      Removes the value at the specified index, provided that this removal is allowed by the parameter multiplicity.
      Specified by:
      remove in interface List<org.opengis.parameter.GeneralParameterValue>
      Overrides:
      remove in class AbstractList<org.opengis.parameter.GeneralParameterValue>
      Parameters:
      index - the index of the value to remove.
      Returns:
      the value removed at the given index.
    • toArray

      public org.opengis.parameter.GeneralParameterValue[] toArray()
      Returns the parameters in an array.
      Specified by:
      toArray in interface Collection<org.opengis.parameter.GeneralParameterValue>
      Specified by:
      toArray in interface List<org.opengis.parameter.GeneralParameterValue>
      Overrides:
      toArray in class AbstractCollection<org.opengis.parameter.GeneralParameterValue>
    • toString

      public String toString()
      Returns a string representation of this list.
      Overrides:
      toString in class AbstractCollection<org.opengis.parameter.GeneralParameterValue>
    • writeObject

      private void writeObject(ObjectOutputStream out) throws IOException
      Trims the array to its capacity before to serialize.
      Parameters:
      out - the output stream where to serialize this object.
      Throws:
      IOException - if an I/O error occurred while writing.