java.lang.Object
de.turnertech.measures.UnitConverter
The UnitConverter handles specialist conversions with more accuracy than would be possible
via conversions to base units. For example if converting from a unit like Kilometer to Nautical
Mile, it is possble that converting first to meters would cause overrun errors or lose accuracy
due to binary limitations.
1. Functions
2. Scalars
3. Divisors (Scalar)
4. Unit Base Unit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MeasureConverts between Units using one of a number of conversion options.static MeasureConverts between Units using one of a number of conversion options.static DoubleUnaryOperatorputFunction(Unit unitIn, Unit unitOut, DoubleUnaryOperator function) Adds a conversion function for transitioning from the unitIn, to the unitOut.static DoubleAdds a scalar function for transitioning from the unitIn, to the unitOut.
-
Constructor Details
-
UnitConverter
public UnitConverter()
-
-
Method Details
-
putScalar
Adds a scalar function for transitioning from the unitIn, to the unitOut. This scalar will also be used as a divisor in the reverse direction.
- Parameters:
unitIn- the Unit in which the in parameter is represented.unitOut- the desired Unit which should be present in the returned.scalar- the scalar.- Returns:
- the result of Map.put(...)
-
putFunction
public static DoubleUnaryOperator putFunction(Unit unitIn, Unit unitOut, DoubleUnaryOperator function) Adds a conversion function for transitioning from the unitIn, to the unitOut. This should be the highest accuracy possible and will be prioritised over other conversion methods.
- Parameters:
unitIn- the Unit in which the in parameter is represented.unitOut- the desired Unit which should be present in the returned.function- the conversion function.- Returns:
- the response to Map.put(...)
-
convert
Converts between Units using one of a number of conversion options. The conversion method used is prioritised to enable accuracy.
- Parameters:
in- Measure to convert.unitOut- Desired output Unit- Returns:
- a measure containing the in parameter represented in the unitOut.
-
convert
Converts between Units using one of a number of conversion options. The conversion method used is prioritised to enable accuracy.
- Conversion Function stored in this class
- Conversion Scalar stored in this class
- Conversion Divisor using the Scalar stored in this class
- Conversion to/from the base Units stored in the Unit class
- Parameters:
in- value to convert between Units.unitIn- the Unit in which the in parameter is represented.unitOut- the desired Unit which should be present in the returned measure- Returns:
- a measure containing the in parameter represented in the unitOut.
- Throws:
UnsupportedOperationException- if conversion is not supported
-