Object
SimpleIdentifiedObject
SimpleParameter
- All Implemented Interfaces:
Cloneable
,Identifier
,GeneralParameterDescriptor
,GeneralParameterValue
,ParameterDescriptor<Double>
,ParameterValue<Double>
,IdentifiedObject
,ReferenceIdentifier
public class SimpleParameter
extends SimpleIdentifiedObject
implements ParameterValue<Double>, ParameterDescriptor<Double>, Cloneable
A
ParameterValue
implementation for double
values.
In order to keep the conceptual model simpler, this parameter value is also its own descriptor.
This is not quite a recommended practice (such descriptors are less suitable for use in HashMap
),
but allows us to keep the amount of classes smaller and closely related interfaces together.
For keeping things yet simpler, the value class is hard-coded as
Double
, the units of measurement are constrained to standard
units (metres, decimal degrees or dimensionless) and we care only about descriptor properties
(minimum, maximum, etc.)
determined by our own SimpleParameter.Type
enumeration. The only mutable property in this class is the
numerical value.
The most interesting methods in this class are:
SimpleIdentifiedObject.getName()
, for the name of this parametergetUnit()
, for the unit of measurement.getMinimumValue()
andgetMaximumValue()
, for the range of valid valuesgetValue()
,doubleValue()
anddoubleValue(Unit)
, for the actual parameter valuesetValue(double)
,setValue(double, Unit)
andsetValue(Object)
, for setting the parameter value
double
. To be strict, all methods working with any value type other
than double
should throw an InvalidParameterTypeException
.
However, this implementation is lenient.- Since:
- 3.1
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Determines the range of values and the unit of measurement of a parameter. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final boolean
Controls whatever this implementation can convert values between thedouble
type and other types.protected final SimpleParameter.Type
The parameter type, which determines the range of values and the unit of measurement.protected double
The parameter value.Fields inherited from class SimpleIdentifiedObject
authority, code
Fields inherited from interface IdentifiedObject
ALIAS_KEY, IDENTIFIERS_KEY, NAME_KEY, REMARKS_KEY
Fields inherited from interface Identifier
AUTHORITY_KEY, CODE_KEY, CODESPACE_KEY, DESCRIPTION_KEY, VERSION_KEY
-
Constructor Summary
ConstructorDescriptionSimpleParameter
(Citation authority, String name, SimpleParameter.Type type) Creates a new parameter of the given authority and name. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the boolean value of an operation parameter.clone()
Returns a copy of this parameter value.double
Returns the numeric value represented by this parameter.double
doubleValue
(Unit<?> unit) Returns the numeric value of the operation parameter in the specified unit of measure.double[]
Returns an ordered sequence numeric values of an operation parameter list, 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
Compares the given object with this parameter for equality.Returns a natural language description of this object.Returns the descriptor of the parameter value.Returns the maximum parameter value, ornull
if none.Returns the minimum parameter value, ornull
if none.Unit<?>
getUnit()
Returns the unit of measurement.getValue()
Returns the parameter value as an object.Unconditionally returnsDouble.class
, which is the hard-coded type of values in this parameter implementation.final TypeName
Unconditionally returns"OGC:Read"
, which is the hard-coded type of values in this parameter implementation.int
hashCode()
Returns a hash code value for this parameter.int
intValue()
Returns the integer value of an operation parameter, usually used for a count.int[]
Returns an ordered sequence integer values of an operation parameter list.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 to the given value and its associated unit.void
setValue
(int value) Sets the parameter value as an integer.void
Sets the parameter value as an object.Returns the string representation of an operation parameter value.toString()
Returns the string representation of this parameter value.Thrown unconditionally the exception, since this parameter implementation cannot represent URI.Methods inherited from class SimpleIdentifiedObject
getAuthority, getCode, getCodeSpace, getDomainOfValidity, getName, getScope, toWKT
Methods inherited from interface GeneralParameterDescriptor
getDirection, getMaximumOccurs, getMinimumOccurs, getName
Methods inherited from interface IdentifiedObject
getAlias, getIdentifiers, getRemarks, toWKT
Methods inherited from interface Identifier
getVersion
Methods inherited from interface ParameterDescriptor
getDefaultValue, getValidValues
-
Field Details
-
LENIENT
protected static final boolean LENIENTControls whatever this implementation can convert values between thedouble
type and other types. Iffalse
, methodsintValue()
,intValueList()
,doubleValueList()
,booleanValue()
andstringValue()
- together with their setter companions - will always throw anInvalidParameterTypeException
. Iftrue
, some conversions will be attempted.This field is defined for two purposes:
- Developers may find convenient to set this field to
false
during debugging, since strict behavior often help to identify unexpected usage of parameters. - This field make easy to spot the codes implementing a lenient behavior. Library implementers may want to remove such codes for making parameters definitively strict.
true
.- See Also:
- Developers may find convenient to set this field to
-
type
The parameter type, which determines the range of values and the unit of measurement. This field can benull
if the parameter type is none of the enumerated ones. -
value
protected double valueThe parameter value. This is the only mutable property of theSimpleParameter
class.- See Also:
-
-
Constructor Details
-
SimpleParameter
Creates a new parameter of the given authority and name.- Parameters:
authority
- organization responsible for definition of the parameter, ornull
.name
- the parameter name.type
- the parameter type, which determines the range of values and the unit of measurement. this argument can benull
if the parameter type is none of the enumerated ones.
-
-
Method Details
-
getDescriptor
Returns the descriptor of the parameter value. Since this simple class implements both the value and the descriptor interfaces, this method returnsthis
. However, more sophisticated libraries are likely to return a different object.- Specified by:
getDescriptor
in interfaceGeneralParameterValue
- Specified by:
getDescriptor
in interfaceParameterValue<Double>
- Returns:
this
descriptor.
-
getDescription
Returns a natural language description of this object. The default implementation returnsnull
.- Specified by:
getDescription
in interfaceGeneralParameterDescriptor
- Specified by:
getDescription
in interfaceIdentifier
- Returns:
- the natural language description, or
null
if none. - See Also:
-
getValueType
Unconditionally returns"OGC:Read"
, which is the hard-coded type of values in this parameter implementation.- Specified by:
getValueType
in interfaceParameterDescriptor<Double>
- Returns:
- the type name of value component(s) in this parameter.
-
getValueClass
Unconditionally returnsDouble.class
, which is the hard-coded type of values in this parameter implementation.- Specified by:
getValueClass
in interfaceParameterDescriptor<Double>
- Returns:
- the type of parameter values.
-
getUnit
public Unit<?> getUnit()Returns the unit of measurement. Because this class implements both the value and descriptor interfaces, the unit of measurement applies to the parameter value as well as the default, the minimum and the maximum values.- Specified by:
getUnit
in interfaceParameterDescriptor<Double>
- Specified by:
getUnit
in interfaceParameterValue<Double>
- Returns:
- the unit of measurement, or
null
if unknown. - See Also:
-
getMinimumValue
Returns the minimum parameter value, ornull
if none. The default implementation infers this property from the type.- Specified by:
getMinimumValue
in interfaceParameterDescriptor<Double>
- Returns:
- the minimum parameter value, or
null
if unbounded. - See Also:
-
getMaximumValue
Returns the maximum parameter value, ornull
if none. The default implementation infers this property from the type.- Specified by:
getMaximumValue
in interfaceParameterDescriptor<Double>
- Returns:
- the maximum parameter value, or
null
if unbounded. - See Also:
-
getValue
Returns the parameter value as an object.- Specified by:
getValue
in interfaceParameterValue<Double>
- Returns:
- the parameter value as an object.
- See Also:
-
doubleValue
public double doubleValue()Returns the numeric value represented by this parameter.- Specified by:
doubleValue
in interfaceParameterValue<Double>
- Returns:
- the numeric value represented by this parameter.
- See Also:
-
doubleValue
Returns the numeric value of the operation parameter in the specified unit of measure. This convenience method applies unit conversion on the fly as needed.- Specified by:
doubleValue
in interfaceParameterValue<Double>
- Parameters:
unit
- the unit of measure for the value to be returned.- Returns:
- the numeric value represented by this parameter after conversion to
unit
. - Throws:
IllegalArgumentException
- if the specified unit is invalid for this parameter.IllegalStateException
- if there is no unit associated to this parameter value.- See Also:
-
intValue
Returns the integer value of an operation parameter, usually used for a count. If lenient, this method returns the value casted to theint
type only if this cast can be done without lost of information. In all other cases an exception is thrown.- Specified by:
intValue
in interfaceParameterValue<Double>
- Returns:
- the numeric value represented by this parameter after conversion to type
int
. - Throws:
InvalidParameterTypeException
- if the value cannot be casted to an integer type.- See Also:
-
booleanValue
Returns the boolean value of an operation parameter. If lenient, this method makes the following choice:- Specified by:
booleanValue
in interfaceParameterValue<Double>
- Returns:
- the boolean value represented by this parameter.
- Throws:
InvalidParameterTypeException
- if the value cannot be converted to a boolean.- See Also:
-
stringValue
Returns the string representation of an operation parameter value. If lenient, this method formats the value as a string and appends the units of measurement, if any.- Specified by:
stringValue
in interfaceParameterValue<Double>
- Returns:
- the numeric value and its units of measurement as a string.
- Throws:
InvalidParameterTypeException
- if the value cannot be converted to a string.- See Also:
-
toString
Returns the string representation of this parameter value. The default implementation returns the concatenation of the identifier string, the" = "
string, then the same string than the string value.- Overrides:
toString
in classSimpleIdentifiedObject
- See Also:
-
doubleValueList
public double[] doubleValueList(Unit<?> unit) throws IllegalArgumentException, IllegalStateException Returns an ordered sequence of numeric values in the specified unit of measure. If lenient, this method returnsdoubleValue(Unit)
in an array of length 1.- Specified by:
doubleValueList
in interfaceParameterValue<Double>
- Parameters:
unit
- the unit of measure for the value to be returned.- Returns:
- the sequence of values represented by this parameter after conversion to type
double
and conversion tounit
. - Throws:
IllegalArgumentException
- if the specified unit is invalid for this parameter.IllegalStateException
- if there is no unit associated to this parameter value.InvalidParameterTypeException
- if the value cannot be converted to an array.- See Also:
-
doubleValueList
Returns an ordered sequence numeric values of an operation parameter list, where each value has the same associated unit of measure. If lenient, this method returnsdoubleValue()
in an array of length 1.- Specified by:
doubleValueList
in interfaceParameterValue<Double>
- Returns:
- the sequence of values represented by this parameter.
- Throws:
InvalidParameterTypeException
- if the value cannot be converted to an array.- See Also:
-
intValueList
Returns an ordered sequence integer values of an operation parameter list. If lenient, this method returnsintValue()
in an array of length 1.- Specified by:
intValueList
in interfaceParameterValue<Double>
- Returns:
- the sequence of values represented by this parameter.
- Throws:
InvalidParameterTypeException
- if the value cannot be converted to an array.- See Also:
-
valueFile
Thrown unconditionally the exception, since this parameter implementation cannot represent URI.- Specified by:
valueFile
in interfaceParameterValue<Double>
- Returns:
- never returned.
- Throws:
InvalidParameterTypeException
- Always thrown.- See Also:
-
setValue
Sets the parameter to the given value and its associated unit. The default implementation converts the given value to the units associated to this parameter, then delegates tosetValue(double)
.- Specified by:
setValue
in interfaceParameterValue<Double>
- Parameters:
value
- the parameter value.unit
- the unit for the specified value.- Throws:
InvalidParameterValueException
- if this parameter cannot be set to the given value.- See Also:
-
setValue
Sets the parameter value as a floating point. This method ensures that the given value is inside the range of valid values, then assign the new value to thevalue
field.- Specified by:
setValue
in interfaceParameterValue<Double>
- Parameters:
value
- the parameter value.- Throws:
InvalidParameterValueException
- if the parameter value is out of range.- See Also:
-
setValue
Sets the parameter value as an array of floating point and their associated unit. If lenient, this method ensures that the array length is exactly 1, then delegates tosetValue(double, Unit)
.- Specified by:
setValue
in interfaceParameterValue<Double>
- Parameters:
values
- the parameter values.unit
- the unit for the specified values.- Throws:
InvalidParameterValueException
- if this parameter cannot be set to the given value.
-
setValue
Sets the parameter value as an integer. If lenient, this method delegates tosetValue(double)
.- Specified by:
setValue
in interfaceParameterValue<Double>
- Parameters:
value
- the parameter value.- Throws:
InvalidParameterValueException
- if this parameter cannot be set to the given value.- See Also:
-
setValue
Sets the parameter value as a boolean. If lenient, the boolean valuetrue
is stored as the numeric value 1 and the boolean valuefalse
is stored as the numeric value 0.- Specified by:
setValue
in interfaceParameterValue<Double>
- Parameters:
value
- the parameter value.- Throws:
InvalidParameterValueException
- if this parameter cannot be set to the given value.- See Also:
-
setValue
Sets the parameter value as an object. If lenient, then the object type can be anyNumber
orCharSequence
parseable as a floating point number. If not lenient, then the type must be restricted toDouble
.- Specified by:
setValue
in interfaceParameterValue<Double>
- Parameters:
value
- the parameter value.- Throws:
InvalidParameterValueException
- if the value cannot be stored as adouble
.- See Also:
-
createValue
Returns a new parameter with the same authority, code and type than this parameter. The value is left to their default value.Implementation note: since this simple class implements both the value and the descriptor interfaces, this method is very similar to theclone()
method. However, in more sophisticated libraries, theParameterDescriptor.createValue()
andParameterValue.clone()
methods are likely to be defined in different objects.- Specified by:
createValue
in interfaceGeneralParameterDescriptor
- Specified by:
createValue
in interfaceParameterDescriptor<Double>
- Returns:
- a new parameter with the same authority, code and type than this parameter.
- See Also:
-
clone
Returns a copy of this parameter value. This method is similar tocreateValue()
except for the following:- This method returns an instance of the same class.
- The value is initialized to the same value than the cloned parameter.
- Specified by:
clone
in interfaceGeneralParameterValue
- Specified by:
clone
in interfaceParameterValue<Double>
- Overrides:
clone
in classObject
- Returns:
- a copy of this parameter value.
- See Also:
-
equals
Compares the given object with this parameter for equality.- Overrides:
equals
in classSimpleIdentifiedObject
- Parameters:
object
- the object to compare with thisSimpleIdentifiedObject
.- Returns:
true
if the given object is equal to this object.
-
hashCode
public int hashCode()Returns a hash code value for this parameter.- Overrides:
hashCode
in classSimpleIdentifiedObject
-