Class IdentityConverter

java.lang.Object
org.apache.sis.measure.AbstractConverter
org.apache.sis.measure.IdentityConverter
All Implemented Interfaces:
Serializable, javax.measure.UnitConverter, LenientComparable

final class IdentityConverter extends AbstractConverter implements LenientComparable
Linear converter with a scale factor of 1 and an offset of 0. We define a class for this special case instead of using the more generic LinearConverter class because we want to avoid performing any arithmetic operation in the convert(double) method, in order to preserve negative zero: When the value is used in a map projection parameter, its sign can have implications in the chain of concatenated transforms. The final result is numerically equivalent, but intermediate steps may differ depending on the parameter sign.
Since:
1.0
Version:
1.0
  • Field Details

    • serialVersionUID

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

      static final IdentityConverter INSTANCE
      The identity linear converter.
  • Constructor Details

    • IdentityConverter

      private IdentityConverter()
      For INSTANCE only.
  • Method Details

    • isLinear

      public boolean isLinear()
      Straight forward implementation.
      Specified by:
      isLinear in interface javax.measure.UnitConverter
      Overrides:
      isLinear in class AbstractConverter
    • isIdentity

      public boolean isIdentity()
      Description copied from class: AbstractConverter
      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
      Overrides:
      isIdentity in class AbstractConverter
    • inverse

      public javax.measure.UnitConverter inverse()
      Specified by:
      inverse in interface javax.measure.UnitConverter
    • convert

      public double convert(double value)
      Specified by:
      convert in interface javax.measure.UnitConverter
    • derivative

      public double derivative(double value)
      Description copied from class: AbstractConverter
      Returns the derivative of the conversion function at the given value, or NaN if unknown.
      Specified by:
      derivative in class AbstractConverter
      Parameters:
      value - the point at which to compute the derivative. Ignored (can be Double.NaN) if the conversion is linear.
    • concatenate

      public javax.measure.UnitConverter concatenate(javax.measure.UnitConverter c)
      Description copied from class: AbstractConverter
      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
      Overrides:
      concatenate in class AbstractConverter
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • convert

      public Number convert(Number value)
      Returns the value unchanged, with a check against null values for consistency with LinearConverter.convert(Number).
      Specified by:
      convert in interface javax.measure.UnitConverter
      Overrides:
      convert in class AbstractConverter
    • hashCode

      public int hashCode()
      Returns a hash code value for this unit converter.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Compares this converter with the given object for equality. This method may return true only if Object is an instance of IdentityConverter or LinearConverter. We apply this restriction in order to be symmetric with those cases, i.e. A.equals(B) = B.equals(A).
      Specified by:
      equals in interface LenientComparable
      Overrides:
      equals in class Object
      Parameters:
      other - the object to compare to this.
      Returns:
      true if both objects are strictly equal.
      See Also:
    • equals

      public boolean equals(Object other, ComparisonMode mode)
      Compares this converter with the given object for equality, optionally ignoring rounding errors.
      Specified by:
      equals in interface LenientComparable
      Parameters:
      other - the object to compare to this.
      mode - the strictness level of the comparison.
      Returns:
      true if both objects are equal according the given comparison mode.
      See Also: