Package javax.measure
Interface UnitConverter
-
public interface UnitConverter
A converter of numeric values between different units.Instances of this class are usually obtained through the
Unit.getConverterTo(Unit)
method.- Since:
- 1.0
- Version:
- 1.0, August 8, 2016
- See Also:
Unit
, Wikipedia: Conversion of units
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description UnitConverter
concatenate(UnitConverter converter)
Concatenates this converter with another converter.double
convert(double value)
Converts adouble
value.java.lang.Number
convert(java.lang.Number value)
Converts aNumber
value.java.util.List<? extends UnitConverter>
getConversionSteps()
Returns the steps of fundamental converters making up this converter orthis
if the converter is a fundamental converter.UnitConverter
inverse()
Returns the inverse of this converter.boolean
isIdentity()
Indicates if this converter is an identity converter.boolean
isLinear()
Indicates if this converter is linear.
-
-
-
Method Detail
-
isIdentity
boolean isIdentity()
Indicates if this converter is an identity converter. The identity converter returns its input argument (convert(x) == x
).- Returns:
true
if this converter is an identity converter.
-
isLinear
boolean isLinear()
Indicates if this converter is linear. A converter is linear if:convert(u + v) == convert(u) + convert(v)
convert(r * u) == r * convert(u)
For linear converters the following property always hold:
y1 = c1.convert(x1); y2 = c2.convert(x2); assert y1*y2 == c1.concatenate(c2).convert(x1*x2);
- Returns:
true
if this converter is linear;false
otherwise.
-
inverse
UnitConverter inverse()
Returns the inverse of this converter. Ifx
is a valid value, thenx == inverse().convert(convert(x))
to within the accuracy of computer arithmetic.- Returns:
- the inverse of this converter.
-
convert
java.lang.Number convert(java.lang.Number value)
Converts aNumber
value.- Parameters:
value
- theNumber
value to convert.- Returns:
- the
Number
value after conversion.
-
convert
double convert(double value)
Converts adouble
value.- Parameters:
value
- the numeric value to convert.- Returns:
- the
double
value after conversion.
-
concatenate
UnitConverter concatenate(UnitConverter converter)
Concatenates this converter with another converter. The resulting converter is equivalent to first converting by the specified converter (right converter), and then converting by this converter (left converter).- Parameters:
converter
- the other converter to concatenate with this converter.- Returns:
- the concatenation of this converter with the other converter.
-
getConversionSteps
java.util.List<? extends UnitConverter> getConversionSteps()
Returns the steps of fundamental converters making up this converter or
this
if the converter is a fundamental converter.For example,
converter1.getConversionSteps()
returnsconverter1
whileconverter1.concatenate(converter2).getConversionSteps()
returnsconverter1, converter2
.- Returns:
- the list of fundamental converters which concatenated make up this converter.
-
-