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.ParameterDescriptorGroupThe descriptor for the list as a whole.private static final longSerial number for inter-operability with different versions.private intNumber of valid elements in thevaluesarray.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 TypeMethodDescriptionbooleanadd(org.opengis.parameter.GeneralParameterValue parameter) Adds aParameterValueor anotherParameterValueGroupto this list.(package private) final voidaddUnchecked(org.opengis.parameter.GeneralParameterValue parameter) Unconditionally adds the given parameter to this list without any validity check.voidclear()Clears this list, then recreate the mandatory parameters.(package private) final org.opengis.parameter.GeneralParameterDescriptordescriptor(int index) Returns the descriptor at the given index.private voidensureCanAdd(org.opengis.parameter.GeneralParameterDescriptor desc) Verifies if adding a parameter with the given descriptor is allowed by the cardinality constraints.private voidensureCanRemove(org.opengis.parameter.GeneralParameterDescriptor desc) Verifies if removing the given value is allowed by the cardinality constraints.(package private) final voidensureDescriptorExists(org.opengis.parameter.GeneralParameterDescriptor desc) Verifies the given descriptor exists in theDefaultParameterDescriptorGroup.descriptors()list.org.opengis.parameter.GeneralParameterValueget(int index) Returns the parameter value at the given index.private voidinitialize(List<org.opengis.parameter.GeneralParameterDescriptor> elements) Adds all mandatory parameters to this list.org.opengis.parameter.GeneralParameterValueremove(int index) Removes the value at the specified index, provided that this removal is allowed by the parameter multiplicity.org.opengis.parameter.GeneralParameterValueset(int index, org.opengis.parameter.GeneralParameterValue parameter) Sets the parameter at the given index.intsize()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 voidTrims 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, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods 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 theListcontract. -
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 thevaluesarray.
-
-
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:
clearin interfaceCollection<org.opengis.parameter.GeneralParameterValue>- Specified by:
clearin interfaceList<org.opengis.parameter.GeneralParameterValue>- Overrides:
clearin classAbstractList<org.opengis.parameter.GeneralParameterValue>
-
size
public int size()Returns the number of parameters in this list.- Specified by:
sizein interfaceCollection<org.opengis.parameter.GeneralParameterValue>- Specified by:
sizein interfaceList<org.opengis.parameter.GeneralParameterValue>- Specified by:
sizein 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 ofUninitializedParameterinstances. -
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:
getin interfaceList<org.opengis.parameter.GeneralParameterValue>- Specified by:
getin 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:
setin interfaceList<org.opengis.parameter.GeneralParameterValue>- Overrides:
setin classAbstractList<org.opengis.parameter.GeneralParameterValue>
-
add
public boolean add(org.opengis.parameter.GeneralParameterValue parameter) Adds aParameterValueor anotherParameterValueGroupto 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 anInvalidParameterCardinalityExceptionwill be thrown.- Specified by:
addin interfaceCollection<org.opengis.parameter.GeneralParameterValue>- Specified by:
addin interfaceList<org.opengis.parameter.GeneralParameterValue>- Overrides:
addin classAbstractList<org.opengis.parameter.GeneralParameterValue>- Parameters:
parameter- new parameter to be added to this group.- Returns:
- always
truesince 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:
removein interfaceList<org.opengis.parameter.GeneralParameterValue>- Overrides:
removein 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:
toArrayin interfaceCollection<org.opengis.parameter.GeneralParameterValue>- Specified by:
toArrayin interfaceList<org.opengis.parameter.GeneralParameterValue>- Overrides:
toArrayin classAbstractCollection<org.opengis.parameter.GeneralParameterValue>
-
toString
Returns a string representation of this list.- Overrides:
toStringin 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.
-