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 Type
    Method
    Description
    Returns a converter that first applies this converter, then the other.
    default double
    convert(double value)
    Converts a value from the source unit to the target unit.
    convert(Real value)
    Converts a value from the source unit to the target unit.
    Returns the derivative of the conversion function at the given value.
    Returns the identity converter.
    Returns the inverse of this converter.
    boolean
    Checks if this converter is an identity converter (no conversion).
    boolean
    Checks if this converter is linear (scale only, no offset).
  • Method Details

    • convert

      Real convert(Real value)
      Converts a value from the source unit to the target unit.
      Parameters:
      value - the value to convert
      Returns:
      the converted value
    • 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

      default UnitConverter concatenate(UnitConverter other)
      Returns a converter that first applies this converter, then the other.

      For example, if this converts meters to feet and other converts 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

      Real derivative(Real value)
      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

      static UnitConverter identity()
      Returns the identity converter.
      Returns:
      the identity converter