Class AbstractConverter

java.lang.Object
org.apache.sis.measure.AbstractConverter
All Implemented Interfaces:
Serializable, javax.measure.UnitConverter
Direct Known Subclasses:
ConcatenatedConverter, IdentityConverter, LinearConverter, PowerOf10, PowerOf10.Logarithm, SexagesimalConverter

abstract class AbstractConverter extends Object implements javax.measure.UnitConverter, Serializable
Base class of unit converters.
Since:
0.8
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final long
    For cross-version compatibility.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) Number[]
    If the conversion can be represented by a polynomial equation, returns the coefficients of that equation.
    javax.measure.UnitConverter
    concatenate(javax.measure.UnitConverter converter)
    Concatenates this converter with another converter.
    convert(Number value)
    Performs a unit conversion on the given number.
    abstract double
    derivative(double value)
    Returns the derivative of the conversion function at the given value, or NaN if unknown.
    (package private) static double
    derivative(javax.measure.UnitConverter converter, double value)
    Delegates to derivative(double) if the given converter is an Apache SIS implementation, or use a fallback otherwise.
    (package private) static double
    Returns the value of the given number, with special handling for Float value on the assumption that the original value was written in base 10.
    (package private) static boolean
    epsilonEquals(double expected, double actual)
    Returns true if the given floating point numbers are considered equal.
    List<javax.measure.UnitConverter>
    Returns the steps of fundamental converters making up this converter.
    boolean
    Returns true if UnitConverter.convert(double) returns given values unchanged.
    boolean
    Indicates if this converter is linear in JSR-363 sense (not the usual mathematical sense).
    (package private) static double
    scale(javax.measure.UnitConverter converter)
    Returns the scale factor of the given converter if the conversion is linear, or NaN otherwise.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface javax.measure.UnitConverter

    convert, inverse
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
  • Constructor Details

    • AbstractConverter

      AbstractConverter()
      Creates a new converter.
  • Method Details

    • isIdentity

      public boolean isIdentity()
      Returns true if UnitConverter.convert(double) returns given values unchanged. The default implementation returns false for convenience of non-linear conversions. Subclasses should override if their conversions may be identity.
      Specified by:
      isIdentity in interface javax.measure.UnitConverter
    • isLinear

      public boolean isLinear()
      Indicates if this converter is linear in JSR-363 sense (not the usual mathematical sense). The default implementation returns false for convenience of non-linear conversions. Subclasses should override if their conversions may be identity.
      Specified by:
      isLinear in interface javax.measure.UnitConverter
    • coefficients

      Number[] coefficients()
      If the conversion can be represented by a polynomial equation, returns the coefficients of that equation. Otherwise returns null.
    • convert

      public Number convert(Number value)
      Performs a unit conversion on the given number. The default implementation delegates to the version working on double primitive type, so it may not provide the accuracy normally required by this method contract. Linear conversions should override this method.
      Specified by:
      convert in interface javax.measure.UnitConverter
    • derivative

      public abstract double derivative(double value)
      Returns the derivative of the conversion function at the given value, or NaN if unknown.
      Parameters:
      value - the point at which to compute the derivative. Ignored (can be Double.NaN) if the conversion is linear.
    • derivative

      static double derivative(javax.measure.UnitConverter converter, double value)
      Delegates to derivative(double) if the given converter is an Apache SIS implementation, or use a fallback otherwise.
    • scale

      static double scale(javax.measure.UnitConverter converter)
      Returns the scale factor of the given converter if the conversion is linear, or NaN otherwise.
    • doubleValue

      static double doubleValue(Number n)
      Returns the value of the given number, with special handling for Float value on the assumption that the original value was written in base 10. This is usually the case for unit conversion factors.
    • epsilonEquals

      static boolean epsilonEquals(double expected, double actual)
      Returns true if the given floating point numbers are considered equal. The tolerance factor used in this method is arbitrary and may change in any future version.
    • concatenate

      public javax.measure.UnitConverter concatenate(javax.measure.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).

      The default implementation is okay, but subclasses should override if they can detect optimizations.

      Specified by:
      concatenate in interface javax.measure.UnitConverter
    • getConversionSteps

      public List<javax.measure.UnitConverter> getConversionSteps()
      Returns the steps of fundamental converters making up this converter. The default implementation returns only this on the assumption that this conversion is not a concatenation of other converters. Subclasses should override if this assumption does not hold.
      Specified by:
      getConversionSteps in interface javax.measure.UnitConverter