|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
Parameters
public final class Parameters
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:
The parameter descriptor may not be always available. For example a user may looks for
the "semi_major" axis length (because it is documented in OGC specification under
that name) but doesn't know and doesn't care about who is providing the implementation. In
such case, he doesn't have the parameter's descriptor. He only have the parameter's name,
and creating a descriptor from that name (a descriptor independent of any implementation)
is tedious.
Parameter descriptors are implementation-dependent. For example if a user searches for
the above-cited "semi_major" axis length using the Geotk's descriptor
for that parameter, we will fail to find this parameter in any alternative
ParameterValueGroup implementations. This is against GeoAPI's inter-operability goal.
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.
| 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
|
cast(ParameterDescriptor<?> descriptor,
Class<T> type)
Casts the given parameter descriptor to the given type. |
|
static
|
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
|
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 |
|---|
public static final ParameterDescriptorGroup EMPTY_GROUP
| Method Detail |
|---|
public static <T> ParameterDescriptor<T> cast(ParameterDescriptor<?> descriptor,
Class<T> type)
throws ClassCastException
T - The expected value class.descriptor - The descriptor to cast, or null.type - The expected value class.
null if the given descriptor was null.
ClassCastException - if the given descriptor doesn't have the expected value class.
public static <T> ParameterValue<T> cast(ParameterValue<?> value,
Class<T> type)
throws ClassCastException
T - The expected value class.value - The value to cast, or null.type - The expected value class.
null if the given value was null.
ClassCastException - if the given value doesn't have the expected value class.public static boolean isValid(ParameterValue<?> value)
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.
value - The parameter to test.
true if the given parameter is valid.
public static ConformanceResult isValid(GeneralParameterValue value,
GeneralParameterDescriptor descriptor)
ParameterValue, then this method
compares the value against the expected
value class, the
[minimum …
maximum] 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.
value - The parameter to test.descriptor - The descriptor to use for fetching the conditions.
pass=true if the parameter is valid. If the parameter is not valid, then
the result explanation gives the
raison.
public static ParameterValue<?> getOrCreate(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
except that this method tries to use an identifier of the same authority than the givenreturn cast(group.parameter(parameter.getName().getCode()));
group if possible.
parameter - The parameter to look for.group - The parameter value group to search into.
ParameterNotFoundException - if the parameter is not valid for the given group.ParameterValueGroup.parameter(String)
public static <T> T value(ParameterDescriptor<T> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
ParameterValue.getValue() method for fetching the value.
T - The type of the parameter value.parameter - The parameter to look for.group - The parameter value group to search into.
null if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static String stringValue(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
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.
parameter - The parameter to look for.group - The parameter value group to search into.
null if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static Boolean booleanValue(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
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.
parameter - The parameter to look for.group - The parameter value group to search into.
null if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static Integer integerValue(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
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.
parameter - The parameter to look for.group - The parameter value group to search into.
null if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static int[] integerValueList(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
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.
parameter - The parameter to look for.group - The parameter value group to search into.
null if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static double doubleValue(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
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.
parameter - The parameter to look for.group - The parameter value group to search into.
NaN if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static double[] doubleValueList(ParameterDescriptor<?> parameter,
ParameterValueGroup group)
throws ParameterNotFoundException
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.
parameter - The parameter to look for.group - The parameter value group to search into.
null if the parameter
is optional and the user didn't provided any value.
ParameterNotFoundException - if the parameter is mandatory and not found in the group.
public static List<GeneralParameterValue> search(GeneralParameterValue parameter,
String name,
int maxDepth)
name is
compared against parameter name and
alias. This method search recursively
in subgroups up to the specified depth:
maxDepth is equal to 0, then this method returns param
if and only if it matches the specified name.maxDepth is equal to 1 and param is an instance of
ParameterDescriptorGroup, then this method checks all elements
in this group but not in subgroups.maxDepth is a high number (e.g. 100), then this method checks all elements
in all subgroups up to the specified depth, which is likely to be never reached. In
this case, maxDepth can be seen as a safeguard against never ending loops, for
example if parameters graph contains cyclic entries.
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.
@Deprecated
public static Map<String,Object> toNameValueMap(GeneralParameterValue parameters,
Map<String,Object> destination)
copy(GeneralParameterValue, Map).
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 - The parameters to extract values from.destination - The destination map, or null for a default one.
destination, or a new map if destination was null.
public static void copy(GeneralParameterValue parameters,
Map<? super String,Object> destination)
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 - The parameters to extract values from.destination - The destination map.
public static void copy(ParameterValueGroup source,
ParameterValueGroup target)
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).
source - The parameters to copy.target - Where to copy the source parameters.
public static boolean ensureSet(ParameterValueGroup parameters,
String name,
double value,
Unit<?> unit,
boolean force)
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 - 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.
true if the were a mismatch, or false if the parameters can be
used with no change.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||