Package org.apache.sis.parameter
Class ParameterValueList
java.lang.Object
java.util.AbstractCollection<E>
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
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 Summary
FieldsModifier and TypeFieldDescription(package private) final org.opengis.parameter.ParameterDescriptorGroup
The descriptor for the list as a whole.private static final long
Serial number for inter-operability with different versions.private int
Number of valid elements in thevalues
array.private org.opengis.parameter.GeneralParameterValue[]
The parameter values in the group.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a parameter list initialized to a copy of the given one.ParameterValueList
(org.opengis.parameter.ParameterDescriptorGroup descriptor) Constructs an initially empty parameter list. -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(org.opengis.parameter.GeneralParameterValue parameter) Adds aParameterValue
or anotherParameterValueGroup
to this list.(package private) final void
addUnchecked
(org.opengis.parameter.GeneralParameterValue parameter) Unconditionally adds the given parameter to this list without any validity check.void
clear()
Clears this list, then recreate the mandatory parameters.(package private) final org.opengis.parameter.GeneralParameterDescriptor
descriptor
(int index) Returns the descriptor at the given index.private void
ensureCanAdd
(org.opengis.parameter.GeneralParameterDescriptor desc) Verifies if adding a parameter with the given descriptor is allowed by the cardinality constraints.private void
ensureCanRemove
(org.opengis.parameter.GeneralParameterDescriptor desc) Verifies if removing the given value is allowed by the cardinality constraints.(package private) final void
ensureDescriptorExists
(org.opengis.parameter.GeneralParameterDescriptor desc) Verifies the given descriptor exists in theDefaultParameterDescriptorGroup.descriptors()
list.org.opengis.parameter.GeneralParameterValue
get
(int index) Returns the parameter value at the given index.private void
initialize
(List<org.opengis.parameter.GeneralParameterDescriptor> elements) Adds all mandatory parameters to this list.org.opengis.parameter.GeneralParameterValue
remove
(int index) Removes the value at the specified index, provided that this removal is allowed by the parameter multiplicity.org.opengis.parameter.GeneralParameterValue
set
(int index, org.opengis.parameter.GeneralParameterValue parameter) Sets the parameter at the given index.int
size()
Returns the number of parameters in this list.org.opengis.parameter.GeneralParameterValue[]
toArray()
Returns the parameters in an array.toString()
Returns a string representation of this list.private void
Trims the array to its capacity before to serialize.Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial number for inter-operability with different versions.- See Also:
-
descriptor
final org.opengis.parameter.ParameterDescriptorGroup descriptorThe descriptor for the list as a whole.This descriptor shall not be used in
AbstractList.equals(Object)
andAbstractList.hashCode()
implementations in order to stay consistent with theList
contract. -
values
private org.opengis.parameter.GeneralParameterValue[] valuesThe parameter values in the group. The length of this array is the list capacity. This array will growth as needed. -
size
private int sizeNumber of valid elements in thevalues
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
Adds all mandatory parameters to this list. This method can be invoked only after construction or after a call toclear()
. -
clear
public void clear()Clears this list, then recreate the mandatory parameters.- Specified by:
clear
in interfaceCollection<org.opengis.parameter.GeneralParameterValue>
- Specified by:
clear
in interfaceList<org.opengis.parameter.GeneralParameterValue>
- Overrides:
clear
in classAbstractList<org.opengis.parameter.GeneralParameterValue>
-
size
public int size()Returns the number of parameters in this list.- Specified by:
size
in interfaceCollection<org.opengis.parameter.GeneralParameterValue>
- Specified by:
size
in interfaceList<org.opengis.parameter.GeneralParameterValue>
- Specified by:
size
in classAbstractCollection<org.opengis.parameter.GeneralParameterValue>
-
descriptor
final org.opengis.parameter.GeneralParameterDescriptor descriptor(int index) Returns the descriptor at the given index. This method is preferable toget(i).getDescriptor()
when the caller does not need the replacement ofUninitializedParameter
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 interfaceList<org.opengis.parameter.GeneralParameterValue>
- Specified by:
get
in classAbstractList<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 theDefaultParameterDescriptorGroup.descriptors()
list, and storing that parameter must be allowed by the cardinality constraints.- Specified by:
set
in interfaceList<org.opengis.parameter.GeneralParameterValue>
- Overrides:
set
in classAbstractList<org.opengis.parameter.GeneralParameterValue>
-
add
public boolean add(org.opengis.parameter.GeneralParameterValue parameter) Adds aParameterValue
or anotherParameterValueGroup
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 bymaximumOccurs
, then anInvalidParameterCardinalityException
will be thrown.- Specified by:
add
in interfaceCollection<org.opengis.parameter.GeneralParameterValue>
- Specified by:
add
in interfaceList<org.opengis.parameter.GeneralParameterValue>
- Overrides:
add
in classAbstractList<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 bymaximumOccurs
.
-
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 theDefaultParameterDescriptorGroup.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 thanAbstractParameterDescriptor.getMaximumOccurs()
, then this method throws anInvalidParameterCardinalityException
. -
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 thanAbstractParameterDescriptor.getMinimumOccurs()
, then this method throws anInvalidParameterCardinalityException
. -
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 interfaceList<org.opengis.parameter.GeneralParameterValue>
- Overrides:
remove
in classAbstractList<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 interfaceCollection<org.opengis.parameter.GeneralParameterValue>
- Specified by:
toArray
in interfaceList<org.opengis.parameter.GeneralParameterValue>
- Overrides:
toArray
in classAbstractCollection<org.opengis.parameter.GeneralParameterValue>
-
toString
Returns a string representation of this list.- Overrides:
toString
in classAbstractCollection<org.opengis.parameter.GeneralParameterValue>
-
writeObject
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.
-