Java Units API
Build 2004-02-06

javax.units
Class Converter

Object
  extended byConverter
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AddConverter, MultiplyConverter

public abstract class Converter
extends Object
implements Serializable

This class represents a converter of numeric values.

It is not required for sub-classes to be immutable (e.g. currency converter).

See Also:
Serialized Form

Field Summary
static Converter IDENTITY
          Holds the identity converter.
 
Constructor Summary
protected Converter()
          Default constructor.
 
Method Summary
 Converter concatenate(Converter converter)
          Concatenates this converter with another converter.
abstract  double convert(double x)
          Converts a double value.
abstract  double derivative(double x)
          Returns this converter derivative for the specified x value.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this converter.
 int hashCode()
          Returns a hash code value for this converter.
abstract  Converter inverse()
          Returns the inverse of this converter.
abstract  boolean isLinear()
          Indicates if this converter is linear.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDENTITY

public static final Converter IDENTITY
Holds the identity converter. This converter does nothing (IDENTITY.convert(x) == x).

Constructor Detail

Converter

protected Converter()
Default constructor.

Method Detail

inverse

public abstract Converter inverse()
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.

Returns:
the inverse of this converter.

convert

public abstract double convert(double x)
                        throws ConversionException
Converts a double value.

Parameters:
x - the numeric value to convert.
Returns:
the converted numeric value.
Throws:
ConversionException - if an error occurs during conversion.

derivative

public abstract double derivative(double x)
Returns this converter derivative for the specified x value. For linear converters, this method returns a constant (the linear factor) for all x values.

Parameters:
x - the value for which the derivative is calculated.
Returns:
the derivative for the specified value.

isLinear

public abstract boolean isLinear()
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).

Returns:
true if this converter is linear; false otherwise.

equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this converter.

Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is a linear converter and this object is also a linear converter and both have same derivatives; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for this converter. Equals object have equal hash codes.

Returns:
this converter hash code value.
See Also:
equals(java.lang.Object)

concatenate

public Converter concatenate(Converter converter)
Concatenates this converter with another converter. The resulting converter is equivalent to first converting by the other converter, and then converting by this converter.

Parameters:
converter - the other converter.
Returns:
the concatenation of this converter with the other converter.

Java Units API
Build 2004-02-06

Symbols, terms and definitions
JSR-108 project