public final class AddConverter extends UnitConverter
This class represents a converter adding a constant offset
(approximated as a double
) to numeric values.
Instances of this class are immutable.
IDENTITY
Constructor and Description |
---|
AddConverter(double offset)
Creates an add converter with the specified offset.
|
Modifier and Type | Method and Description |
---|---|
UnitConverter |
concatenate(UnitConverter converter)
Concatenates this converter with another converter.
|
double |
convert(double amount)
Converts a double value.
|
double |
getOffset()
Returns the offset value for this add converter.
|
UnitConverter |
inverse()
Returns the inverse of this converter.
|
boolean |
isLinear()
Indicates if this converter is linear.
|
equals, hashCode
public AddConverter(double offset)
offset
- the offset value.java.lang.IllegalArgumentException
- if offset is zero (or close to zero).public double getOffset()
public UnitConverter inverse()
UnitConverter
x
is a valid
value, then x == inverse().convert(convert(x))
to within
the accuracy of computer arithmetic.inverse
in class UnitConverter
public double convert(double amount)
UnitConverter
convert
in class UnitConverter
amount
- the numeric value to convert.public boolean isLinear()
UnitConverter
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]isLinear
in class UnitConverter
true
if this converter is linear;
false
otherwise.public UnitConverter concatenate(UnitConverter converter)
UnitConverter
Note: Implementations must ensure that the UnitConverter.IDENTITY
instance
is returned if the resulting converter is an identity
converter.
concatenate
in class UnitConverter
converter
- the other converter.