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.4, May 12, 2019
- Author:
- Jean-Marie Dautelle, Werner Keil, Martin Desruisseaux, Thodoris Bais, Andi Huber
- See Also:
Unit, Wikipedia: Conversion of units
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description UnitConverterconcatenate(UnitConverter converter)Concatenates this converter with another converter.doubleconvert(double value)Converts adoublevalue.java.lang.Numberconvert(java.lang.Number value)Converts aNumbervalue.java.util.List<? extends UnitConverter>getConversionSteps()Returns the steps of fundamental converters making up this converter orthisif the converter is a fundamental converter.UnitConverterinverse()Returns the inverse of this converter.booleanisIdentity()Indicates if this converter is an identity converter.booleanisLinear()Indicates whether this converter represents a (one-dimensional) linear transformation, that is a linear map (wikipedia) from a one-dimensional vector space (a scalar) to a one-dimensional vector space.
-
-
-
Method Detail
-
isIdentity
boolean isIdentity()
Indicates if this converter is an identity converter. The identity converter returns its input argument (convert(x) == x).Note: Identity converters are also always 'linear', see
isLinear().- Returns:
trueif this converter is an identity converter.
-
isLinear
boolean isLinear()
Indicates whether this converter represents a (one-dimensional) linear transformation, that is a linear map (wikipedia) from a one-dimensional vector space (a scalar) to a one-dimensional vector space. Typically from 'R' to 'R', with 'R' the real numbers.Given such a 'linear' converter 'A', let 'u', 'v' and 'r' be arbitrary numbers, then the following must hold by definition:
A(u + v) == A(u) + A(v)A(r * u) == r * A(u)
Given a second 'linear' converter 'B', commutativity of composition follows by above definition:
(A o B) (u) == (B o A) (u)
A(B(u)) == B(A(u)), meaning for 'A' and 'B' the order of their composition does not matter. Expressed as Java code:
Note: For composing UnitConverters see alsoA.concatenate(B).convert(u) == B.concatenate(A).convert(u)concatenate(UnitConverter).- Returns:
trueif this converter represents a linear transformation;falseotherwise.
-
inverse
UnitConverter inverse()
Returns the inverse of this converter. Ifxis 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 aNumbervalue.- Parameters:
value- theNumbervalue to convert.- Returns:
- the
Numbervalue after conversion.
-
convert
double convert(double value)
Converts adoublevalue.- Parameters:
value- the numeric value to convert.- Returns:
- the
doublevalue 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
thisif the converter is a fundamental converter.For example,
converter1.getConversionSteps()returnsconverter1whileconverter1.concatenate(converter2).getConversionSteps()returnsconverter1, converter2.- Returns:
- the list of fundamental converters which concatenated make up this converter.
-
-