Package org.opengis.example.parameter
Class SimpleParameter
- Object
-
- SimpleIdentifiedObject
-
- SimpleParameter
-
- All Implemented Interfaces:
Serializable,Cloneable,Identifier,GeneralParameterDescriptor,GeneralParameterValue,ParameterDescriptor<Double>,ParameterValue<Double>,IdentifiedObject,ReferenceIdentifier
public class SimpleParameter extends SimpleIdentifiedObject implements ParameterValue<Double>, ParameterDescriptor<Double>, Cloneable
AParameterValueimplementation fordoublevalues. 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 inHashMap), but allow 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 ownSimpleParameter.Typeenumeration. 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 thandoubleshould throw anInvalidParameterTypeException. However this implementation is lenient.- Since:
- 3.1
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimpleParameter.TypeDetermines the range of values and the unit of measurement of a parameter.
-
Field Summary
Fields Modifier and Type Field Description protected static booleanLENIENTControls whatever this implementation can convert values between thedoubletype and other types.protected SimpleParameter.TypetypeThe parameter type, which determines the range of values and the unit of measurement.protected doublevalueThe 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
Constructors Constructor Description SimpleParameter(Citation authority, String name, SimpleParameter.Type type)Creates a new parameter of the given authority and name.
-
Method Summary
Modifier and Type Method Description booleanbooleanValue()Returns the boolean value of an operation parameter.SimpleParameterclone()Returns a copy of this parameter value.SimpleParametercreateValue()doubledoubleValue()Returns the numeric value represented by this parameter.doubledoubleValue(Unit<?> unit)Returns the numeric value of the operation parameter in the specified unit of measure.double[]doubleValueList()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.booleanequals(Object object)Compares the given object with this parameter for equality.InternationalStringgetDescription()Returns a natural language description of this object.ParameterDescriptor<Double>getDescriptor()Returns the descriptor of the parameter value.ParameterDirectiongetDirection()Returnsthis, since this simple class is used only as input parameter.Comparable<Double>getMaximumValue()Returns the maximum parameter value, ornullif none.Comparable<Double>getMinimumValue()Returns the minimum parameter value, ornullif none.Unit<?>getUnit()Returns the unit of measurement.DoublegetValue()Returns the parameter value as an object.Class<Double>getValueClass()Unconditionally returnsDouble.class, which is the hard-coded type of values in this parameter implementation.inthashCode()Returns a hash code value for this parameter.intintValue()Returns the integer value of an operation parameter, usually used for a count.int[]intValueList()Returns an ordered sequence integer values of an operation parameter list.voidsetValue(boolean value)Sets the parameter value as a boolean.voidsetValue(double value)Sets the parameter value as a floating point.voidsetValue(double[] values, Unit<?> unit)Sets the parameter value as an array of floating point and their associated unit.voidsetValue(double value, Unit<?> unit)Sets the parameter to the given value and its associated unit.voidsetValue(int value)Sets the parameter value as an integer.voidsetValue(Object value)Sets the parameter value as an object.StringstringValue()Returns the string representation of an operation parameter value.StringtoString()Returns the string representation of this parameter value.URIvalueFile()Thrown unconditionally the exception, since this parameter implementation can not represent URI.-
Methods inherited from class SimpleIdentifiedObject
getAuthority, getCode, getCodeSpace, getDomainOfValidity, getName, getScope, toWKT
-
Methods inherited from interface GeneralParameterDescriptor
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 Detail
-
LENIENT
protected static final boolean LENIENT
Controls whatever this implementation can convert values between thedoubletype 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
falseduring 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 implementors may want to remove such codes for making parameters definitively strict.
true.- See Also:
- Constant Field Values
- Developers may find convenient to set this field to
-
type
protected final SimpleParameter.Type type
The parameter type, which determines the range of values and the unit of measurement. This field can benullif the parameter type is none of the enumerated ones.
-
value
protected double value
The parameter value. This is the only mutable property of theSimpleParameterclass.- See Also:
doubleValue(),setValue(double)
-
-
Constructor Detail
-
SimpleParameter
public SimpleParameter(Citation authority, String name, SimpleParameter.Type type)
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 benullif the parameter type is none of the enumerated ones.
-
-
Method Detail
-
getDescriptor
public ParameterDescriptor<Double> 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:
getDescriptorin interfaceGeneralParameterValue- Specified by:
getDescriptorin interfaceParameterValue<Double>
-
getDescription
public InternationalString getDescription()
Returns a natural language description of this object. The default implementation returnsnull.- Specified by:
getDescriptionin interfaceGeneralParameterDescriptor- Specified by:
getDescriptionin interfaceIdentifier- Returns:
- the natural language description, or
nullif none.
-
getDirection
public ParameterDirection getDirection()
Returnsthis, since this simple class is used only as input parameter.- Specified by:
getDirectionin interfaceGeneralParameterDescriptor
-
getValueClass
public Class<Double> getValueClass()
Unconditionally returnsDouble.class, which is the hard-coded type of values in this parameter implementation.- Specified by:
getValueClassin interfaceParameterDescriptor<Double>
-
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:
getUnitin interfaceParameterDescriptor<Double>- Specified by:
getUnitin interfaceParameterValue<Double>- Returns:
- the unit of measurement, or
nullif unknown.
-
getMinimumValue
public Comparable<Double> getMinimumValue()
Returns the minimum parameter value, ornullif none. The default implementation infers this property from the type.- Specified by:
getMinimumValuein interfaceParameterDescriptor<Double>- Returns:
- the minimum parameter value, or
nullif unbounded.
-
getMaximumValue
public Comparable<Double> getMaximumValue()
Returns the maximum parameter value, ornullif none. The default implementation infers this property from the type.- Specified by:
getMaximumValuein interfaceParameterDescriptor<Double>- Returns:
- the maximum parameter value, or
nullif unbounded.
-
getValue
public Double getValue()
Returns the parameter value as an object.- Specified by:
getValuein interfaceParameterValue<Double>- Returns:
- the parameter value as an object.
-
doubleValue
public double doubleValue()
Returns the numeric value represented by this parameter.- Specified by:
doubleValuein interfaceParameterValue<Double>- Returns:
- the numeric value represented by this parameter.
-
doubleValue
public double doubleValue(Unit<?> unit) throws IllegalArgumentException, IllegalStateExceptionReturns 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:
doubleValuein 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.
-
intValue
public int intValue() throws InvalidParameterTypeExceptionReturns the integer value of an operation parameter, usually used for a count. If lenient, this method returns the value casted to theinttype only if this cast can be done without lost of information. In all other cases an exception is thrown.- Specified by:
intValuein interfaceParameterValue<Double>- Returns:
- the numeric value represented by this parameter after conversion to type
int. - Throws:
InvalidParameterTypeException- if the value can not be casted to an integer type.
-
booleanValue
public boolean booleanValue() throws InvalidParameterTypeExceptionReturns the boolean value of an operation parameter. If lenient, this method makes the following choice:- Specified by:
booleanValuein interfaceParameterValue<Double>- Returns:
- the boolean value represented by this parameter.
- Throws:
InvalidParameterTypeException- if the value can not be converted to a boolean.
-
stringValue
public String stringValue() throws InvalidParameterTypeException
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:
stringValuein interfaceParameterValue<Double>- Returns:
- the numeric value and its units of measurement as a string.
- Throws:
InvalidParameterTypeException- if the value can not be converted to a string.- See Also:
toString()
-
toString
public String 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:
toStringin classSimpleIdentifiedObject- See Also:
stringValue()
-
doubleValueList
public double[] doubleValueList(Unit<?> unit) throws IllegalArgumentException, IllegalStateExceptionReturns 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:
doubleValueListin interfaceParameterValue<Double>- 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 can not be converted to an array.
-
doubleValueList
public double[] doubleValueList() throws InvalidParameterTypeExceptionReturns 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:
doubleValueListin interfaceParameterValue<Double>- Returns:
- the sequence of values represented by this parameter.
- Throws:
InvalidParameterTypeException- if the value can not be converted to an array.
-
intValueList
public int[] intValueList() throws InvalidParameterTypeExceptionReturns an ordered sequence integer values of an operation parameter list. If lenient, this method returnsintValue()in an array of length 1.- Specified by:
intValueListin interfaceParameterValue<Double>- Returns:
- the sequence of values represented by this parameter.
- Throws:
InvalidParameterTypeException- if the value can not be converted to an array.
-
valueFile
public URI valueFile() throws InvalidParameterTypeException
Thrown unconditionally the exception, since this parameter implementation can not represent URI.- Specified by:
valueFilein interfaceParameterValue<Double>- Returns:
- never returned.
- Throws:
InvalidParameterTypeException- Always thrown.
-
setValue
public void setValue(double value, Unit<?> unit) throws InvalidParameterValueExceptionSets 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:
setValuein interfaceParameterValue<Double>- Parameters:
value- the parameter value.unit- the unit for the specified value.- Throws:
InvalidParameterValueException- if this parameter can not be set to the given value.
-
setValue
public void setValue(double value) throws InvalidParameterValueExceptionSets 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 thevaluefield.- Specified by:
setValuein interfaceParameterValue<Double>- Throws:
InvalidParameterValueException- if the parameter value is out of range.
-
setValue
public void setValue(double[] values, Unit<?> unit) throws InvalidParameterValueExceptionSets 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:
setValuein interfaceParameterValue<Double>- Parameters:
values- the parameter values.unit- the unit for the specified values.- Throws:
InvalidParameterValueException- if this parameter can not be set to the given value.
-
setValue
public void setValue(int value) throws InvalidParameterValueExceptionSets the parameter value as an integer. If lenient, this method delegates tosetValue(double).- Specified by:
setValuein interfaceParameterValue<Double>- Throws:
InvalidParameterValueException- if this parameter can not be set to the given value.
-
setValue
public void setValue(boolean value) throws InvalidParameterValueExceptionSets the parameter value as a boolean. If lenient, the boolean valuetrueis stored as the numeric value 1 and the boolean valuefalseis stored as the numeric value 0.- Specified by:
setValuein interfaceParameterValue<Double>- Throws:
InvalidParameterValueException- if this parameter can not be set to the given value.
-
setValue
public void setValue(Object value) throws InvalidParameterValueException
Sets the parameter value as an object. If lenient, then the object type can be anyNumberorCharSequenceparseable as a floating point number. If not lenient, then the type must be restricted toDouble.- Specified by:
setValuein interfaceParameterValue<Double>- Parameters:
value- the parameter value.- Throws:
InvalidParameterValueException- if the value can not be stored as adouble.
-
createValue
public SimpleParameter 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:
createValuein interfaceGeneralParameterDescriptor- Specified by:
createValuein interfaceParameterDescriptor<Double>- Returns:
- a new parameter with the same authority, code and type than this parameter.
- See Also:
clone()
-
clone
public SimpleParameter 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:
clonein interfaceGeneralParameterValue- Specified by:
clonein interfaceParameterValue<Double>- Overrides:
clonein classObject- See Also:
createValue()
-
equals
public boolean equals(Object object)
Compares the given object with this parameter for equality.- Overrides:
equalsin classSimpleIdentifiedObject- Parameters:
object- the object to compare with thisSimpleIdentifiedObject.- Returns:
trueif the given object is equals to this object.
-
hashCode
public int hashCode()
Returns a hash code value for this parameter.- Overrides:
hashCodein classSimpleIdentifiedObject
-
-