org.geotoolkit.parameter
Class Parameters

Object
  extended by Static
      extended by Parameters

public final class Parameters
extends Static

Utility class for methods helping implementing, and working with the parameter API from org.opengis.parameter package. This class provides methods for searching, setting a value, etc. from a parameter name. Names in simple String form are preferred over the full ParameterDescriptor object because:

When a method in this class expects a full ParameterDescriptor object in argument (for example value(ParameterDescriptor, ParameterValueGroup)), the descriptor name and alias are used for the search - this class does not look for strictly equal ParameterDescriptor objects.

Since:
2.1
Version:
3.18
Author:
Jody Garnett (Refractions), Martin Desruisseaux (IRD, Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Field Summary
static ParameterDescriptorGroup EMPTY_GROUP
          An empty parameter group.
 
Method Summary
static Boolean booleanValue(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the parameter value as a boolean for the given descriptor.
static
<T> ParameterDescriptor<T>
cast(ParameterDescriptor<?> descriptor, Class<T> type)
          Casts the given parameter descriptor to the given type.
static
<T> ParameterValue<T>
cast(ParameterValue<?> value, Class<T> type)
          Casts the given parameter value to the given type.
static void copy(GeneralParameterValue parameters, Map<? super String,Object> destination)
          Gets the name-value pairs.
static void copy(ParameterValueGroup source, ParameterValueGroup target)
          Copies all parameter values from source to target.
static double doubleValue(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the parameter value as a floating point number for the given descriptor.
static double[] doubleValueList(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the parameter value as a list of floating point numbers for the given descriptor.
static boolean ensureSet(ParameterValueGroup parameters, String name, double value, Unit<?> unit, boolean force)
          Ensures that the specified parameter is set.
static ParameterValue<?> getOrCreate(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the value of the given parameter in the given group if defined, or create a default parameter otherwise.
static Integer integerValue(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the parameter value as an integer for the given descriptor.
static int[] integerValueList(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the parameter value as a list of integers for the given descriptor.
static ConformanceResult isValid(GeneralParameterValue value, GeneralParameterDescriptor descriptor)
          Checks a parameter value against the conditions specified by the given descriptor.
static boolean isValid(ParameterValue<?> value)
          Checks a parameter value against its parameter descriptor.
static List<GeneralParameterValue> search(GeneralParameterValue parameter, String name, int maxDepth)
          Searches all parameters with the specified name.
static String stringValue(ParameterDescriptor<?> parameter, ParameterValueGroup group)
          Returns the parameter value as a string for the given descriptor.
static Map<String,Object> toNameValueMap(GeneralParameterValue parameters, Map<String,Object> destination)
          Deprecated. Replaced by copy(GeneralParameterValue, Map).
static
<T> T
value(ParameterDescriptor<T> parameter, ParameterValueGroup group)
          Returns the parameter value as an object for the given descriptor.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_GROUP

public static final ParameterDescriptorGroup EMPTY_GROUP
An empty parameter group. This group contains no parameters.

Method Detail

cast

public static <T> ParameterDescriptor<T> cast(ParameterDescriptor<?> descriptor,
                                              Class<T> type)
                                   throws ClassCastException
Casts the given parameter descriptor to the given type. An exception is thrown immediately if the parameter does not have the expected value class. This is a helper method for type safety when using Java 5 parameterized types.

Type Parameters:
T - The expected value class.
Parameters:
descriptor - The descriptor to cast, or null.
type - The expected value class.
Returns:
The descriptor casted to the given type, or null if the given descriptor was null.
Throws:
ClassCastException - if the given descriptor doesn't have the expected value class.
Since:
2.5

cast

public static <T> ParameterValue<T> cast(ParameterValue<?> value,
                                         Class<T> type)
                              throws ClassCastException
Casts the given parameter value to the given type. An exception is thrown immediately if the parameter does not have the expected value class. This is a helper method for type safety when using Java 5 parameterized types.

Type Parameters:
T - The expected value class.
Parameters:
value - The value to cast, or null.
type - The expected value class.
Returns:
The value casted to the given type, or null if the given value was null.
Throws:
ClassCastException - if the given value doesn't have the expected value class.
Since:
2.5

isValid

public static boolean isValid(ParameterValue<?> value)
Checks a parameter value against its parameter descriptor. This method compares the value against the expected value class, the [minimummaximum] range and the set of valid values.

This is a convenience method for testing a single parameter value assuming that its descriptor is correct. It returns a boolean because in case of failure, the faulty parameter is known: it is the one given in argument to this method. For a more generic test which can work on group of parameters and provide more details about which parameter failed and why, use the isValid(GeneralParameterValue, GeneralParameterDescriptor) method instead.

Parameters:
value - The parameter to test.
Returns:
true if the given parameter is valid.

isValid

public static ConformanceResult isValid(GeneralParameterValue value,
                                        GeneralParameterDescriptor descriptor)
Checks a parameter value against the conditions specified by the given descriptor. If the given parameter is an instance of ParameterValue, then this method compares the value against the expected value class, the [minimummaximum] range and the set of valid values. If this method is an instance of ParameterValueGroup, then the check is applied recursively for every parameter in this group.

Parameters:
value - The parameter to test.
descriptor - The descriptor to use for fetching the conditions.
Returns:
A conformance result having the attribute pass=true if the parameter is valid. If the parameter is not valid, then the result explanation gives the raison.
Since:
3.05

getOrCreate

public static ParameterValue<?> getOrCreate(ParameterDescriptor<?> parameter,
                                            ParameterValueGroup group)
                                     throws ParameterNotFoundException
Returns the value of the given parameter in the given group if defined, or create a default parameter otherwise. This method is equivalent to:
return cast(group.parameter(parameter.getName().getCode()));
except that this method tries to use an identifier of the same authority than the given group if possible.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter object.
Throws:
ParameterNotFoundException - if the parameter is not valid for the given group.
Since:
3.18
See Also:
ParameterValueGroup.parameter(String)

value

public static <T> T value(ParameterDescriptor<T> parameter,
                          ParameterValueGroup group)
               throws ParameterNotFoundException
Returns the parameter value as an object for the given descriptor. The method uses the ParameterValue.getValue() method for fetching the value.

Type Parameters:
T - The type of the parameter value.
Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or null if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.00

stringValue

public static String stringValue(ParameterDescriptor<?> parameter,
                                 ParameterValueGroup group)
                          throws ParameterNotFoundException
Returns the parameter value as a string for the given descriptor. This method uses the ParameterValue.stringValue() method for fetching the value. Note that the result may be different than the above value method if the ParameterValue implementation performs string conversions.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or null if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.00

booleanValue

public static Boolean booleanValue(ParameterDescriptor<?> parameter,
                                   ParameterValueGroup group)
                            throws ParameterNotFoundException
Returns the parameter value as a boolean for the given descriptor. This method uses the ParameterValue.booleanValue() method for fetching the value. Note that the result may be different than the above value method if the ParameterValue implementation performs numeric conversions.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or null if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.18

integerValue

public static Integer integerValue(ParameterDescriptor<?> parameter,
                                   ParameterValueGroup group)
                            throws ParameterNotFoundException
Returns the parameter value as an integer for the given descriptor. This method uses the ParameterValue.intValue() method for fetching the value. Note that the result may be different than the above value method if the ParameterValue implementation performs numeric conversions.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or null if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.00

integerValueList

public static int[] integerValueList(ParameterDescriptor<?> parameter,
                                     ParameterValueGroup group)
                              throws ParameterNotFoundException
Returns the parameter value as a list of integers for the given descriptor. This method uses the ParameterValue.intValueList() method for fetching the values. Note that the result may be different than the above value method if the ParameterValue implementation performs numeric conversions.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or null if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.18

doubleValue

public static double doubleValue(ParameterDescriptor<?> parameter,
                                 ParameterValueGroup group)
                          throws ParameterNotFoundException
Returns the parameter value as a floating point number for the given descriptor. Values are automatically converted into the standard units specified by the supplied param argument.

This method uses the ParameterValue.doubleValue(Unit) method for fetching the value. Note that the result may be different than the above value method if the ParameterValue implementation performs numeric conversions.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or NaN if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.00

doubleValueList

public static double[] doubleValueList(ParameterDescriptor<?> parameter,
                                       ParameterValueGroup group)
                                throws ParameterNotFoundException
Returns the parameter value as a list of floating point numbers for the given descriptor. Values are automatically converted into the standard units specified by the supplied param argument.

This method uses the ParameterValue.doubleValueList(Unit) method for fetching the values. Note that the result may be different than the above value method if the ParameterValue implementation performs numeric conversions.

Parameters:
parameter - The parameter to look for.
group - The parameter value group to search into.
Returns:
The requested parameter value, or null if the parameter is optional and the user didn't provided any value.
Throws:
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
Since:
3.18

search

public static List<GeneralParameterValue> search(GeneralParameterValue parameter,
                                                 String name,
                                                 int maxDepth)
Searches all parameters with the specified name. The given name is compared against parameter name and alias. This method search recursively in subgroups up to the specified depth:

Parameters:
parameter - The parameter to inspect.
name - The name of the parameter to search for. See the class javadoc for a rational about the usage of name as a key instead of descriptor.
maxDepth - The maximal depth while descending down the parameter tree.
Returns:
The set (possibly empty) of parameters with the given name.

toNameValueMap

@Deprecated
public static Map<String,Object> toNameValueMap(GeneralParameterValue parameters,
                                                           Map<String,Object> destination)
Deprecated. Replaced by copy(GeneralParameterValue, Map).

Gets a flat view of name-value pairs. This method copies all parameter values into the supplied destination map. Keys are parameter names as String objects, and values are parameter values as arbitrary objects. All subgroups (if any) are extracted recursively.

Parameters:
parameters - The parameters to extract values from.
destination - The destination map, or null for a default one.
Returns:
destination, or a new map if destination was null.

copy

public static void copy(GeneralParameterValue parameters,
                        Map<? super String,Object> destination)
Gets the name-value pairs. This method copies all parameter values into the supplied destination map. Keys are parameter names as String objects, and values are parameter values as arbitrary objects.

If the given parameters is a group having sub-groups, then all subgroups are extracted recursively with their keys prefixed by the sub-groups name followed by the default namespace separator.

This map provides a convenient way to copy the content of a ParameterValueGroup to a Properties instance.

Parameters:
parameters - The parameters to extract values from.
destination - The destination map.
Since:
3.18

copy

public static void copy(ParameterValueGroup source,
                        ParameterValueGroup target)
Copies all parameter values from source to target. A typical usage of this method is for transferring values from an arbitrary implementation to some specific implementation (e.g. a parameter group implementation backed by a ParameterBlock for image processing operations).

Parameters:
source - The parameters to copy.
target - Where to copy the source parameters.
Since:
2.2

ensureSet

public static boolean ensureSet(ParameterValueGroup parameters,
                                String name,
                                double value,
                                Unit<?> unit,
                                boolean force)
Ensures that the specified parameter is set. The value is set if and only if no value were already set by the user for the given name.

The force argument said what to do if the named parameter is already set. If the value matches, nothing is done in all case. If there is a mismatch and force is true, then the parameter is overridden with the specified value. Otherwise, the parameter is left unchanged but a warning is logged with the FINE level.

Parameters:
parameters - The set of projection parameters.
name - The parameter name to set.
value - The value to set, or to expect if the parameter is already set.
unit - The value unit.
force - true for forcing the parameter to the specified value is case of mismatch.
Returns:
true if the were a mismatch, or false if the parameters can be used with no change.


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.