javax.measure.converter
Class AffineConverter

java.lang.Object
  extended by javax.measure.converter.UnitConverter
      extended by javax.measure.converter.AffineConverter
All Implemented Interfaces:
Serializable

public final class AffineConverter
extends UnitConverter

This class represents an converter using long parameters of the form (num*value+off)/den.

Instances of this class are immutable.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.measure.converter.UnitConverter
IDENTITY
 
Constructor Summary
protected AffineConverter(double num_, double off_, double den_)
          Creates an add converter with the specified offset.
 
Method Summary
 UnitConverter concatenate(UnitConverter converter)
          Concatenates this converter with another converter.
 double convert(double amount)
          Converts a double value.
 boolean equals(Object obj)
          Indicates whether this converter is considered the same as the converter specified (they must be of same types).
 double getDen()
           
 double getNum()
           
 double getOff()
           
 int hashCode()
          Returns a hash code value for this converter.
 UnitConverter inverse()
          Returns the inverse of this converter.
 boolean isLinear()
          Indicates if this converter is linear.
static UnitConverter valueOf(double num, double off, double den)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AffineConverter

protected AffineConverter(double num_,
                          double off_,
                          double den_)
Creates an add converter with the specified offset.

Parameters:
num_ - numerator scaling value
off_ - offset added to scaled value
den_ - denominator of both numerator and offset
Throws:
IllegalArgumentException - if offset is zero (or close to zero).
Method Detail

getNum

public double getNum()

getOff

public double getOff()

getDen

public double getDen()

inverse

public UnitConverter inverse()
Description copied from class: UnitConverter
Returns the inverse of this converter. If x is a valid value, then x == inverse().convert(convert(x)) to within the accuracy of computer arithmetic.

Specified by:
inverse in class UnitConverter
Returns:
the inverse of this converter.

convert

public double convert(double amount)
Description copied from class: UnitConverter
Converts a double value.

Specified by:
convert in class UnitConverter
Parameters:
amount - the numeric value to convert.
Returns:
the converted numeric value.

isLinear

public boolean isLinear()
Description copied from class: UnitConverter
Indicates if this converter is linear. A converter is linear if convert(u + v) == convert(u) + convert(v) and convert(r * u) == r * convert(u). For linear converters the following property always hold:[code] y1 = c1.convert(x1); y2 = c2.convert(x2); then y1*y2 = c1.concatenate(c2).convert(x1*x2)[/code]

Specified by:
isLinear in class UnitConverter
Returns:
true if this converter is linear; false otherwise.

equals

public boolean equals(Object obj)
Description copied from class: UnitConverter
Indicates whether this converter is considered the same as the converter specified (they must be of same types).

Specified by:
equals in class UnitConverter
Parameters:
obj - the converter with which to compare.
Returns:
true if the specified object is a converter considered equals to this converter;false otherwise.

hashCode

public int hashCode()
Description copied from class: UnitConverter
Returns a hash code value for this converter. Equals object have equal hash codes.

Specified by:
hashCode in class UnitConverter
Returns:
this converter hash code value.
See Also:
UnitConverter.equals(java.lang.Object)

concatenate

public UnitConverter concatenate(UnitConverter converter)
Description copied from class: UnitConverter
Concatenates this converter with another converter. The resulting converter is equivalent to first converting by the specified converter, and then converting by this converter.

Note: Implementations must ensure that the UnitConverter.IDENTITY instance is returned if the resulting converter is an identity converter.

Overrides:
concatenate in class UnitConverter
Parameters:
converter - the other converter.
Returns:
the concatenation of this converter with the other converter.

valueOf

public static UnitConverter valueOf(double num,
                                    double off,
                                    double den)


Copyright © 2007 Sentilla Corporation. All Rights Reserved.