Interface UnitConverter
- All Known Implementing Classes:
AddConverter, CompositeConverter, IdentityConverter, LogConverter, MultiplyConverter, RationalConverter
public interface UnitConverter
Converts values between compatible units of measurement.
Unit converters provide transformation between different units of the same dimension. Converters are composable and can be chained or combined.
Example Usage:
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Method Summary
Modifier and TypeMethodDescriptiondefault UnitConverterconcatenate(UnitConverter other) Returns a converter that first applies this converter, then the other.default doubleconvert(double value) Converts a value from the source unit to the target unit.Converts a value from the source unit to the target unit.derivative(Real value) Returns the derivative of the conversion function at the given value.static UnitConverteridentity()Returns the identity converter.inverse()Returns the inverse of this converter.booleanChecks if this converter is an identity converter (no conversion).booleanisLinear()Checks if this converter is linear (scale only, no offset).
-
Method Details
-
convert
-
convert
default double convert(double value) Converts a value from the source unit to the target unit.- Parameters:
value- the value to convert- Returns:
- the converted value
-
inverse
UnitConverter inverse()Returns the inverse of this converter.The inverse converter performs the reverse transformation.
- Returns:
- the inverse converter
-
concatenate
Returns a converter that first applies this converter, then the other.For example, if this converts meters to feet and
otherconverts feet to miles, the result converts meters to miles.- Parameters:
other- the converter to apply after this one- Returns:
- the concatenated converter
-
isIdentity
boolean isIdentity()Checks if this converter is an identity converter (no conversion).- Returns:
- true if this is the identity converter
-
isLinear
boolean isLinear()Checks if this converter is linear (scale only, no offset).Linear converters satisfy: f(x + y) = f(x) + f(y) and f(ax) = aâ‹…f(x).
- Returns:
- true if this converter is linear
-
derivative
Returns the derivative of the conversion function at the given value.For linear converters, this is constant. For affine converters (like temperature), this is also constant.
- Parameters:
value- the value at which to evaluate the derivative- Returns:
- the derivative (conversion rate)
-
identity
-