org.geotoolkit.parameter
Class FloatParameter

Object
  extended by FormattableObject
      extended by AbstractParameter
          extended by AbstractParameterValue<Double>
              extended by FloatParameter
All Implemented Interfaces:
Serializable, Cloneable, Formattable, GeneralParameterValue, ParameterValue<Double>

public class FloatParameter
extends AbstractParameterValue<Double>

A parameter value as a floating point (double precision) number. This class provides the same functionalities than Parameter, except that:

When those conditions are meet, FloatParameter is slightly more efficient than Parameter since it avoid the creation of Double wrapper objects.


Implementation note for subclasses
Except for the constructors, the equals(Object) and the hashCode() methods, all read and write operations ultimately delegates to the following methods:

Consequently, the above-cited methods provide single points that subclasses can override for modifying the behavior of all getter and setter methods.

Since:
2.0
Version:
3.20
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
DefaultParameterDescriptor, ParameterGroup, Serialized Form
Module:
referencing/geotk-referencing (download)    View source code for this class

Constructor Summary
FloatParameter(ParameterDescriptor<Double> descriptor)
          Constructs a parameter from the specified descriptor.
FloatParameter(ParameterDescriptor<Double> descriptor, double value)
          Constructs a parameter from the specified descriptor and value.
 
Method Summary
 boolean booleanValue()
          Returns true if the value is different from 0, or false otherwise.
 FloatParameter clone()
          Returns a clone of this parameter.
 double doubleValue()
          Returns the numeric value represented by this operation parameter.
 double doubleValue(Unit<?> unit)
          Returns the numeric value of the coordinate operation parameter in the specified unit of measure.
 double[] doubleValueList()
          Wraps the value in an array of length 0 or 1.
 double[] doubleValueList(Unit<?> unit)
          Wraps the value in an array of length 0 or 1.
 boolean equals(Object object)
          Compares the specified object with this parameter for equality.
 Unit<?> getUnit()
          Returns the unit of measure of the parameter value.
 Double getValue()
          Returns the parameter value as a Double, or null if none.
 int hashCode()
          Returns a hash value for this parameter.
 int intValue()
          Returns the numeric value casted to integer.
 int[] intValueList()
          Wraps the value in an array of length 1.
 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)
          If the length of the given array is 1, delegates to setValue(double, 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 a Double object.
 String stringValue()
          Returns the string representation of the value.
 URI valueFile()
          Always throws an exception, since this parameter is not an URI.
 
Methods inherited from class AbstractParameterValue
addChangeListener, getDescriptor, removeChangeListener
 
Methods inherited from class AbstractParameter
formatWKT, toString, write
 
Methods inherited from class FormattableObject
print, toWKT, toWKT
 
Methods inherited from class Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FloatParameter

public FloatParameter(ParameterDescriptor<Double> descriptor)
Constructs a parameter from the specified descriptor.

Parameters:
descriptor - The abstract definition of this parameter.
Throws:
IllegalArgumentException - if the value class is not Double.class.

FloatParameter

public FloatParameter(ParameterDescriptor<Double> descriptor,
                      double value)
Constructs a parameter from the specified descriptor and value. This convenience constructor is equivalents to the one-argument constructor followed by a call to setValue(double).

Parameters:
descriptor - The abstract definition of this parameter.
value - The parameter value.
Throws:
IllegalArgumentException - if the value class is not Double.class.
Method Detail

getUnit

public Unit<?> getUnit()
Returns the unit of measure of the parameter value. The default value is ParameterDescriptor.getUnit().

Implementation note for subclasses
All getter methods which need unit information will invoke this getUnit() method. Subclasses can override this method if they need to compute the unit dynamically.

Returns:
The unit of measure, or null if none.

doubleValue

public double doubleValue(Unit<?> unit)
                   throws IllegalArgumentException
Returns the numeric value of the coordinate operation parameter in the specified unit of measure. This convenience method applies unit conversions on the fly as needed.

Parameters:
unit - The unit of measure for the value to be returned.
Returns:
The numeric value represented by this parameter after conversion to unit, or Double.NaN if none.
Throws:
IllegalArgumentException - if the specified unit is invalid for this parameter.

doubleValue

public double doubleValue()
Returns the numeric value represented by this operation parameter. The units of measurement are specified by getUnit().

Implementation note for subclasses
All getter methods will invoke this doubleValue() method. Subclasses can override this method if they need to compute the value dynamically.

Returns:
The numeric value represented by this parameter, or Double.NaN if none.

intValue

public int intValue()
             throws IllegalStateException
Returns the numeric value casted to integer. If the current double value can not be casted without precision loss, then this method throws an exception.

Returns:
The numeric value represented by this parameter after conversion to type int.
Throws:
InvalidParameterTypeException - If the value can not be casted to integer.
IllegalStateException - if the value is not defined and there is no default value.

booleanValue

public boolean booleanValue()
                     throws IllegalStateException
Returns true if the value is different from 0, or false otherwise.

Returns:
The boolean value represented by this parameter.
Throws:
IllegalStateException - if the value is not defined and there is no default value.

stringValue

public String stringValue()
                   throws IllegalStateException
Returns the string representation of the value.

Returns:
The string value represented by this parameter.
Throws:
IllegalStateException - if the value is not defined and there is no default value.

doubleValueList

public double[] doubleValueList(Unit<?> unit)
                         throws IllegalArgumentException
Wraps the value in an array of length 0 or 1.

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 to unit.
Throws:
IllegalArgumentException - if the specified unit is invalid for this parameter.

doubleValueList

public double[] doubleValueList()
Wraps the value in an array of length 0 or 1.

Returns:
The sequence of values represented by this parameter.

intValueList

public int[] intValueList()
                   throws InvalidParameterTypeException
Wraps the value in an array of length 1.

Returns:
The sequence of values represented by this parameter.
Throws:
InvalidParameterTypeException - If the value can not be casted to integer.

valueFile

public URI valueFile()
              throws InvalidParameterTypeException
Always throws an exception, since this parameter is not an URI.

Returns:
Never return.
Throws:
InvalidParameterTypeException - The value is not a reference to a file or an URI.

getValue

public Double getValue()
Returns the parameter value as a Double, or null if none.

Returns:
The parameter value as an object, or null if the current value is Double.NaN.

setValue

public void setValue(double value,
                     Unit<?> unit)
              throws InvalidParameterValueException
Sets the parameter value as a floating point and its associated unit. The default implementation verifies the arguments validity, then stores the given values.

Implementation note for subclasses
This method is invoked by all other setXXX(…) methods. Subclasses can override this method if they want to perform more processing on the value before its storage, or to be notified about value changes.

Parameters:
value - The parameter value.
unit - The new unit of measurement.
Throws:
InvalidParameterValueException - if the value is illegal for some reason (for example a value out of range).

setValue

public void setValue(double value)
              throws InvalidParameterValueException
Sets the parameter value as a floating point. The default implementation delegates to setValue(double, Unit).

Parameters:
value - The parameter value.
Throws:
InvalidParameterValueException - if the value is illegal for some reason (for example a value out of range).

setValue

public void setValue(int value)
              throws InvalidParameterValueException
Sets the parameter value as an integer. The default implementation delegates to setValue(double).

Parameters:
value - The parameter value.
Throws:
InvalidParameterValueException - if the value is illegal for some reason (for example a value out of range).

setValue

public void setValue(boolean value)
              throws InvalidParameterValueException
Sets the parameter value as a boolean. The default implementation delegates to setValue(double) with value 1 for true or 0 or false.

Parameters:
value - The parameter value.
Throws:
InvalidParameterValueException - if the boolean type is inappropriate for this parameter.

setValue

public void setValue(Object value)
              throws InvalidParameterValueException
Sets the parameter value as a Double object. The default implementation ensures that the given value is a Number, then delegates to setValue(double).

Parameters:
value - The parameter value, or null for Double.NaN.
Throws:
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).

setValue

public void setValue(double[] values,
                     Unit<?> unit)
              throws InvalidParameterValueException
If the length of the given array is 1, delegates to setValue(double, Unit). Otherwise throws an exception, since this parameter does not accept arbitrary arrays.

Throws:
InvalidParameterValueException

equals

public boolean equals(Object object)
Compares the specified object with this parameter for equality.

Overrides:
equals in class AbstractParameter
Parameters:
object - The object to compare to this.
Returns:
true if both objects are equal.

hashCode

public int hashCode()
Returns a hash value for this parameter.

Overrides:
hashCode in class AbstractParameter
Returns:
The hash code value. This value doesn't need to be the same in past or future versions of this class.

clone

public FloatParameter clone()
Returns a clone of this parameter.

Specified by:
clone in interface GeneralParameterValue
Specified by:
clone in interface ParameterValue<Double>
Overrides:
clone in class AbstractParameterValue<Double>
Returns:
A copy of this object.
See Also:
Object.clone()


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