javax.measure.converter
public abstract class UnitConverter extends java.lang.Object implements java.io.Serializable
This class represents a converter of numeric values.
It is not required for sub-classes to be immutable (e.g. currency converter).
Sub-classes must ensure unicity of the identity converter. In other words, if the result of an
operation is equivalent to the identity converter, then the unique IDENTITY instance should be returned.
| Modifier and Type | Field and Description |
|---|---|
static UnitConverter |
IDENTITY
Holds the identity converter (unique).
|
| Modifier | Constructor and Description |
|---|---|
protected |
UnitConverter()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
UnitConverter |
concatenate(UnitConverter converter)
Concatenates this converter with another converter.
|
abstract double |
convert(double x)
Converts a double value.
|
boolean |
equals(java.lang.Object cvtr)
Indicates whether this converter is considered the same as the converter specified.
|
int |
hashCode()
Returns a hash code value for this converter.
|
abstract UnitConverter |
inverse()
Returns the inverse of this converter.
|
abstract boolean |
isLinear()
Indicates if this converter is linear.
|
public static final UnitConverter IDENTITY
ONE.convert(x) == x).public abstract UnitConverter inverse()
x is a valid value, then
x == inverse().convert(convert(x)) to within the accuracy of computer arithmetic.public abstract double convert(double x)
throws ConversionException
x - the numeric value to convert.ConversionException - if an error occurs during conversion.public abstract boolean isLinear()
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]true if this converter is linear; false otherwise.public boolean equals(java.lang.Object cvtr)
IDENTITY.equals in class java.lang.Objectcvtr - the converter with which to compare.true if the specified object is a converter considered equals to this converter;
false otherwise.public int hashCode()
hashCode in class java.lang.Objectequals(java.lang.Object)public UnitConverter concatenate(UnitConverter converter)
Note: Implementations must ensure that the IDENTITY instance is returned if the resulting converter is
an identity converter.
converter - the other converter.