T
- The value type.public class DefaultParameterValue<T> extends FormattableObject implements ParameterValue<T>, Serializable, Cloneable
ParameterValue
instances are elements in
a parameter value group, in a way similar to Map.Entry
instances in a java.util.Map
.
In the context of coordinate operations, most parameter values are numeric and can be obtained by the
intValue()
or doubleValue()
methods. But other types of parameter values are possible
and can be handled by the more generic getValue()
and setValue(Object)
methods.
All xxxValue()
methods in this class are convenience methods converting the value from Object
to some commonly used types. Those types are specified in ISO 19111 as an union of attributes, listed below with
the corresponding getter and setter methods:
ISO attribute | Java type | Getter method | Setter method |
---|---|---|---|
Object | getValue() | setValue(Object) | |
stringValue | String | stringValue() | setValue(Object) |
value | double | doubleValue() | setValue(double) |
double | doubleValue(Unit) | setValue(double, Unit) | |
valueList | double[] | doubleValueList() | setValue(Object) |
double[] | doubleValueList(Unit) | setValue(double[], Unit) | |
integerValue | int | intValue() | setValue(int) |
integerValueList | int[] | intValueList() | setValue(Object) |
booleanValue | boolean | booleanValue() | setValue(boolean) |
valueFile | URI | valueFile() | setValue(Object) |
valueFileCitation | Citation | getValue() | setValue(Object) |
Class<T> valueClass = parameter.getDescriptor().getValueClass();
DefaultParameterValue(ParameterDescriptor)
constructor or by a call to the
ParameterDescriptor.createValue()
method. The later is recommended since it allows descriptors to return
specialized implementations.
equals(Object)
and hashCode()
)
ultimately delegates to the following methods:
getValue()
and getUnit()
(if needed),
then perform their processing on the values returned by those methods.setValue(Object, Unit)
method.DefaultParameterDescriptor
,
DefaultParameterValueGroup
,
Serialized FormDefined in the sis-referencing
module
Constructor and Description |
---|
DefaultParameterValue(ParameterDescriptor<T> descriptor)
Creates a parameter value from the specified descriptor.
|
DefaultParameterValue(ParameterValue<T> parameter)
Creates a new instance initialized with the values from the specified parameter object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
booleanValue()
Returns the boolean value of this parameter.
|
DefaultParameterValue<T> |
clone()
Returns a clone of this parameter value.
|
double |
doubleValue()
Returns the numeric value of this parameter.
|
double |
doubleValue(Unit<?> unit)
Returns the numeric value of this parameter in the given unit of measure.
|
double[] |
doubleValueList()
Returns an ordered sequence of two or more numeric values of this parameter,
where each value has the same associated unit of measure.
|
double[] |
doubleValueList(Unit<?> unit)
Returns an ordered sequence of numeric values in the specified unit of measure.
|
boolean |
equals(Object object)
Compares the specified object with this parameter for equality.
|
protected String |
formatTo(Formatter formatter)
Formats this parameter as a Well Known Text
Parameter[…] element. |
ParameterDescriptor<T> |
getDescriptor()
Returns the definition of this parameter.
|
Unit<?> |
getUnit()
Returns the unit of measure of the parameter value.
|
T |
getValue()
Returns the parameter value as an object.
|
int |
hashCode()
Returns a hash value for this parameter.
|
int |
intValue()
Returns the integer value of this parameter, usually used for a count.
|
int[] |
intValueList()
Returns an ordered sequence of two or more integer values of this parameter, usually used for counts.
|
void |
setValue(boolean value)
Sets the parameter value as a boolean.
|
void |
setValue(double value)
Sets the parameter value as a floating point.
|
void |
setValue(double[] values,
Unit<?> unit)
Sets the parameter value as an array of floating point and their associated unit.
|
void |
setValue(double value,
Unit<?> unit)
Sets the parameter value as a floating point and its associated unit.
|
void |
setValue(int value)
Sets the parameter value as an integer.
|
void |
setValue(Object value)
Sets the parameter value as an object.
|
protected void |
setValue(Object value,
Unit<?> unit)
Sets the parameter value and its associated unit.
|
String |
stringValue()
Returns the string value of this parameter.
|
protected void |
validate(T value)
Invoked by
setValue(Object, Unit) after the basic verifications have been done and before
the value is stored. |
URI |
valueFile()
Returns a reference to a file or a part of a file containing one or more parameter values.
|
print, toString, toString, toWKT
public DefaultParameterValue(ParameterDescriptor<T> descriptor)
descriptor
- The abstract definition of this parameter.public DefaultParameterValue(ParameterValue<T> parameter)
parameter
- The parameter to copy values from.public ParameterDescriptor<T> getDescriptor()
getDescriptor
in interface GeneralParameterValue
getDescriptor
in interface ParameterValue<T>
public Unit<?> getUnit()
String
type),
then this method returns null
. Note that "no unit" does not mean "dimensionless".
getUnit()
method.
Subclasses can override this method if they need to compute the unit dynamically.getUnit
in interface ParameterValue<T>
null
if none.doubleValue()
,
doubleValueList()
,
getValue()
public T getValue()
getValue()
method.
Subclasses can override this method if they need to compute the value dynamically.getValue
in interface ParameterValue<T>
null
if no value has been set
and there is no default value.setValue(Object)
public boolean booleanValue() throws IllegalStateException
The default implementation invokes getValue()
and casts the result if possible,
or throws an exception otherwise.
booleanValue
in interface ParameterValue<T>
InvalidParameterTypeException
- if the value is not a boolean type.IllegalStateException
- if the value is not defined and there is no default value.setValue(boolean)
public int intValue() throws IllegalStateException
The default implementation invokes getValue()
and casts the result if possible,
or throws an exception otherwise.
intValue
in interface ParameterValue<T>
int
.InvalidParameterTypeException
- if the value is not an integer type.IllegalStateException
- if the value is not defined and there is no default value.setValue(int)
,
intValueList()
public int[] intValueList() throws IllegalStateException
The default implementation invokes getValue()
and casts the result if possible,
or throws an exception otherwise. If the value can be casted, then the array is cloned before
to be returned.
intValueList
in interface ParameterValue<T>
InvalidParameterTypeException
- if the value is not an array of int
s.IllegalStateException
- if the value is not defined and there is no default value.setValue(Object)
,
intValue()
public double doubleValue() throws IllegalStateException
getUnit()
.
The default implementation invokes getValue()
and casts the result if possible,
or throws an exception otherwise.
doubleValue
in interface ParameterValue<T>
double
.
This method returns Double.NaN
only if such "value" has been explicitely set.InvalidParameterTypeException
- if the value is not a numeric type.IllegalStateException
- if the value is not defined and there is no default value.getUnit()
,
setValue(double)
,
doubleValueList()
public double[] doubleValueList() throws IllegalStateException
The default implementation invokes getValue()
and casts the result if possible,
or throws an exception otherwise. If the value can be casted, then the array is cloned before
to be returned.
doubleValueList
in interface ParameterValue<T>
InvalidParameterTypeException
- if the value is not an array of double
s.IllegalStateException
- if the value is not defined and there is no default value.getUnit()
,
setValue(Object)
,
doubleValue()
public double doubleValue(Unit<?> unit) throws IllegalArgumentException, IllegalStateException
The default implementation invokes doubleValue()
and getUnit()
,
then converts the values to the given unit of measurement.
doubleValue
in interface ParameterValue<T>
unit
- The unit of measure for the value to be returned.double
and conversion to unit
.IllegalArgumentException
- if the specified unit is invalid for this parameter.InvalidParameterTypeException
- if the value is not a numeric type.IllegalStateException
- if the value is not defined and there is no default value.getUnit()
,
setValue(double,Unit)
,
doubleValueList(Unit)
public double[] doubleValueList(Unit<?> unit) throws IllegalArgumentException, IllegalStateException
The default implementation invokes doubleValueList()
and getUnit()
,
then converts the values to the given unit of measurement.
doubleValueList
in interface ParameterValue<T>
unit
- The unit of measure for the value to be returned.double
and conversion to unit
.IllegalArgumentException
- if the specified unit is invalid for this parameter.InvalidParameterTypeException
- if the value is not an array of double
s.IllegalStateException
- if the value is not defined and there is no default value.getUnit()
,
setValue(double[],Unit)
,
doubleValue(Unit)
public String stringValue() throws IllegalStateException
stringValue
in interface ParameterValue<T>
InvalidParameterTypeException
- if the value is not a string.IllegalStateException
- if the value is not defined and there is no default value.getValue()
,
setValue(Object)
public URI valueFile() throws IllegalStateException
URI
, URL
, File
.valueFile
in interface ParameterValue<T>
InvalidParameterTypeException
- if the value is not a reference to a file or an URI.IllegalStateException
- if the value is not defined and there is no default value.getValue()
,
setValue(Object)
public void setValue(Object value) throws InvalidParameterValueException
Double
,
double[]
, Integer
, int[]
, Boolean
, String
or URI
.
If the given value is null
, then this parameter is set to the
default value.
The default implementation delegates to setValue(Object, Unit)
.
This implementation does not clone the given value. In particular, references to int[]
and double[]
arrays are stored as-is.
setValue
in interface ParameterValue<T>
value
- The parameter value, or null
to restore the default.InvalidParameterValueException
- if the type of value
is inappropriate for this parameter,
or if the value is illegal for some other reason (for example the value is numeric and out of range).getValue()
public void setValue(boolean value) throws InvalidParameterValueException
The default implementation delegates to setValue(Object, Unit)
.
setValue
in interface ParameterValue<T>
value
- The parameter value.InvalidParameterValueException
- if the boolean type is inappropriate for this parameter.booleanValue()
public void setValue(int value) throws InvalidParameterValueException
The default implementation wraps the given integer in an object of the type specified by the
descriptor, then delegates to setValue(Object, Unit)
.
setValue
in interface ParameterValue<T>
value
- The parameter value.InvalidParameterValueException
- if the integer type is inappropriate for this parameter,
or if the value is illegal for some other reason (for example a value out of range).intValue()
public void setValue(double value) throws InvalidParameterValueException
The default implementation wraps the given number in an object of the type specified by the
descriptor, then delegates to setValue(Object, Unit)
.
setValue
in interface ParameterValue<T>
value
- The parameter value.InvalidParameterValueException
- if the floating point type is inappropriate for this
parameter, or if the value is illegal for some other reason (for example a value out
of range).setValue(double,Unit)
,
doubleValue()
public void setValue(double value, Unit<?> unit) throws InvalidParameterValueException
The default implementation wraps the given number in an object of the type specified by the
descriptor, then delegates to setValue(Object, Unit)
.
setValue
in interface ParameterValue<T>
value
- The parameter value.unit
- The unit for the specified value.InvalidParameterValueException
- if the floating point type is inappropriate for this parameter,
or if the value is illegal for some other reason (for example a value out of range).setValue(double)
,
doubleValue(Unit)
public void setValue(double[] values, Unit<?> unit) throws InvalidParameterValueException
The default implementation delegates to setValue(Object, Unit)
.
setValue
in interface ParameterValue<T>
values
- The parameter values.unit
- The unit for the specified value.InvalidParameterValueException
- if the floating point array type is inappropriate for this parameter,
or if the value is illegal for some other reason (for example a value out of range).protected void setValue(Object value, Unit<?> unit) throws InvalidParameterValueException
null
, then this parameter is set to the
default value.
Current implementation does not clone the given value. In particular, references to
int[]
and double[]
arrays are stored as-is.
value
- The parameter value, or null
to restore the default.unit
- The unit associated to the new parameter value, or null
.InvalidParameterValueException
- if the type of value
is inappropriate for this parameter,
or if the value is illegal for some other reason (for example the value is numeric and out of range).protected void validate(T value) throws InvalidParameterValueException
setValue(Object, Unit)
after the basic verifications have been done and before
the value is stored. Subclasses can override this method for performing additional verifications.
ParameterValue
, since the later value will be stored in the unit specified by the user.
value
- The value converted to the unit of measurement specified by the descriptor.InvalidParameterValueException
- If the given value is invalid for implementation-specific reasons.public boolean equals(Object object)
public int hashCode()
public DefaultParameterValue<T> clone()
clone
in interface GeneralParameterValue
clone
in interface ParameterValue<T>
clone
in class Object
protected String formatTo(Formatter formatter)
Parameter[…]
element.
Example:
Parameter["False easting", 0.0, LengthUnit["metre", 1]]
formatTo
in class FormattableObject
formatter
- The formatter where to format the inner content of this WKT element."Parameter"
.FormattableObject.toWKT()
,
FormattableObject.toString()
Copyright © 2010–2014 The Apache Software Foundation. All rights reserved.