Object
Parameters
DefaultParameterValueGroup
- All Implemented Interfaces:
Serializable,Cloneable,LenientComparable,GeneralParameterValue,ParameterValueGroup
public class DefaultParameterValueGroup
extends Parameters
implements LenientComparable, Serializable
A group of related parameter values. Parameter groups have some similarities with
java.util.Map:
parameter(String)is similar in purpose toMap.get(Object), with an additional level of indirection in both the argument and the return value.values()is similar in purpose toMap.entrySet(), withParameterValueplaying a role similar toMap.Entry.
Instantiation and validity constraints
ParameterValueGroup instances are typically created by calls to
descriptor.createValue() on a descriptor
supplied by a coordinate operation or process provider. New instances are initialized with a list of values containing all mandatory parameters, and no optional parameter. The values list is modifiable, but
all methods will first ensure that the modification would not violate the cardinality constraints (i.e. the minimum
and maximum occurrences of that parameter allowed by the descriptor). If a cardinality constraint is violated, then
an InvalidParameterCardinalityException will be thrown.
Setting the parameter values
After a newParameterValueGroup instance has been created, the parameter values can be set by chaining
calls to parameter(String) with one of the setValue(…) methods defined in the returned object
(see the table of setter methods). The parameter(String) method can
be invoked regardless of whether the parameter is mandatory or optional: if the parameter was optional and not
yet present in this group, it will be created.
Example 1
Assuming the descriptor defined in theDefaultParameterDescriptorGroup example,
one can set Mercator (variant A) projection parameters as below:
ParameterValueGroup mercator = Mercator.PARAMETERS.createValue();
mercator.parameter("Longitude of natural origin").setValue(-60, Units.DEGREE); // 60°W
mercator.parameter("Latitude of natural origin") .setValue( 40, Units.DEGREE); // 40°N
// Keep default values for other parameters.
Example 2
Alternatively, if all parameters were created elsewhere and the user wants to copy them in a new parameter group, theList.addAll(Collection) method can be invoked on the values list.
ParameterValue<?>[] parameter = ...; // Defined elsewhere.
ParameterValueGroup mercator = Mercator.PARAMETERS.createValue();
Collections.addAll(mercator.values(), parameters);
Removing elements
Optional parameters can be removed by the usualList.remove(int) or List.remove(Object)
operations on the values list. But attempts to remove a mandatory parameter will cause an
InvalidParameterCardinalityException to be thrown.
Calls to values().clear() restore this DefaultParameterValueGroup to its initial state.
- Since:
- 0.4
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a parameter group from the specified descriptor.DefaultParameterValueGroup(ParameterValueGroup parameters) Creates a new instance initialized with all values from the specified parameter group. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new subgroup of the specified name, and adds it to the list of subgroups.clone()Returns a deep copy of this group of parameter values.final booleanCompares the specified object with this parameter for equality.booleanequals(Object object, ComparisonMode mode) Compares the specified object with this parameter for equality.Returns the abstract definition of this group of parameters.<T> ParameterValue<T> getOrCreate(ParameterDescriptor<T> parameter) Returns the parameter identified by the given descriptor.Returns all subgroups with the specified name.intReturns a hash value for this parameter.Returns the value in this group for the specified name.values()Returns the values in this group.Methods inherited from class Parameters
booleanValue, cast, cast, castOrWrap, copy, doubleValue, doubleValue, doubleValueList, getDescriptors, getMandatoryValue, getMemberName, getValue, getValueDomain, intValue, intValueList, isUnmodifiable, print, stringValue, toString, unmodifiable, unmodifiable
-
Constructor Details
-
DefaultParameterValueGroup
Creates a parameter group from the specified descriptor.Usage note
ParameterValueGroupare usually not instantiated directly. Instead, consider invokingdescriptor.createValue()on a descriptor supplied by a map projection or process provider.- Parameters:
descriptor- the descriptor for this group.
-
DefaultParameterValueGroup
Creates a new instance initialized with all values from the specified parameter group. This is a shallow copy constructor, since the values contained in the given group is not cloned.- Parameters:
parameters- The parameters to copy values from.- Since:
- 0.6
- See Also:
-
-
Method Details
-
getDescriptor
Returns the abstract definition of this group of parameters.- Specified by:
getDescriptorin interfaceGeneralParameterValue- Specified by:
getDescriptorin interfaceParameterValueGroup- Returns:
- the abstract definition of this group of parameters.
-
values
Returns the values in this group. The returned list is live: changes in this list are reflected on thisParameterValueGroup, and conversely.Restrictions
All write operations must comply to the following conditions:- Parameters added to the list shall have one of the descriptors listed by
getDescriptor(). - Adding or removing parameters shall not violate the parameter cardinality constraints.
InvalidParameterNameException,InvalidParameterCardinalityExceptionor other runtime exceptions if a condition is not met.- Specified by:
valuesin interfaceParameterValueGroup- Returns:
- the values in this group.
- Parameters added to the list shall have one of the descriptors listed by
-
getOrCreate
public <T> ParameterValue<T> getOrCreate(ParameterDescriptor<T> parameter) throws ParameterNotFoundException Returns the parameter identified by the given descriptor. If the identified parameter is optional and not yet created, then it will be created now.- Overrides:
getOrCreatein classParameters- Type Parameters:
T- the type of the parameter value.- Parameters:
parameter- the parameter to look for.- Returns:
- the requested parameter instance.
- Throws:
ParameterNotFoundException- if the givenparametername or alias is not legal for this group.- See Also:
-
parameter
Returns the value in this group for the specified name. This method performs the first applicable action in the following choices:- If this group contains a parameter value of the given name, then that parameter is returned.
- Otherwise if a descriptor of the
given name exists, then a new
ParameterValueinstance is created, added to this group and returned. - Otherwise a
ParameterNotFoundExceptionis thrown.
double easting = parameter("False easting" ).doubleValue(); double northing = parameter("False northing").doubleValue(); parameter("False easting").setValue(500000.0);API note: there is noparameters(String)method returning a list of parameter values because the ISO 19111 standard fixes theParameterValuemaximum occurrence to 1.Parameters subgroups
This method does not search recursively in subgroups. This is because more than one subgroup may exist for the same descriptor. The user have to query all subgroups and select explicitly the appropriate one.- Specified by:
parameterin interfaceParameterValueGroup- Parameters:
name- the name of the parameter to search for.- Returns:
- the parameter value for the given name.
- Throws:
ParameterNotFoundException- if there is no parameter value for the given name.- See Also:
-
groups
Returns all subgroups with the specified name. Groups are listed in the order they were added by calls toaddGroup(String).This method does not create new groups: if the requested group is optional (i.e.
minimumOccurs == 0) and no value were defined previously, then this method returns an empty set.- Specified by:
groupsin interfaceParameterValueGroup- Parameters:
name- the name of the parameter to search for.- Returns:
- the list of all parameter group for the given name, in insertion order.
- Throws:
ParameterNotFoundException- if no descriptor was found for the given name.
-
addGroup
public ParameterValueGroup addGroup(String name) throws ParameterNotFoundException, InvalidParameterCardinalityException Creates a new subgroup of the specified name, and adds it to the list of subgroups. The argument shall be the name of a descriptor group which is a child of this group.Group removal
There is noremoveGroup(String)method. To remove a group, users can inspect thegroups(String)orvalues()list, decide which occurrences to remove if there is many of them for the same name, and whether to iterate recursively into sub-groups or not.- Specified by:
addGroupin interfaceParameterValueGroup- Parameters:
name- the name of the parameter group to create.- Returns:
- a newly created parameter group for the given name.
- Throws:
ParameterNotFoundException- if no descriptor was found for the given name.InvalidParameterCardinalityException- if this parameter group already contains the maximum number of occurrences of subgroups of the given name.
-
equals
Compares the specified object with this parameter for equality. The strictness level is controlled by the second argument:ComparisonMode.STRICTandBY_CONTRACTtake in account the parameter order.ComparisonMode.IGNORE_METADATAandAPPROXIMATEignore the order of parameter values (but not necessarily the order of parameter descriptors).
- Specified by:
equalsin interfaceLenientComparable- Parameters:
object- the object to compare tothis.mode- the strictness level of the comparison.- Returns:
trueif both objects are equal according the given comparison mode.- See Also:
-
equals
Compares the specified object with this parameter for equality. This method is implemented as below:Subclasses shall overridereturn equals(other, ComparisonMode.STRICT);equals(Object, ComparisonMode)instead of this method.- Specified by:
equalsin interfaceLenientComparable- Overrides:
equalsin classObject- Parameters:
object- the object to compare tothis.- Returns:
trueif both objects are equal.- See Also:
-
hashCode
public int hashCode()Returns a hash value for this parameter. -
clone
Returns a deep copy of this group of parameter values. Included parameter values and subgroups are cloned recursively.- Specified by:
clonein interfaceGeneralParameterValue- Specified by:
clonein interfaceParameterValueGroup- Overrides:
clonein classParameters- Returns:
- a copy of this group of parameter values.
- See Also:
-