# Class AbstractConverter

Object
AbstractConverter

All Implemented Interfaces:
  `Serializable, UnitConverter`

public abstract class AbstractConverter extends Object implements UnitConverter, Serializable
Skeletal implementation of the `UnitConverter` interface for reducing implementation effort. This class makes easier to define a non-linear conversion between two units of measurement. Note that for linear conversions, the standard `Unit​.shift(Number)`, `Unit​.multiply(Number)` and `Unit​.divide(Number)` methods should be used instead.

After a non-linear conversion has been created, a new unit of measurement using that conversion can be defined by a call to `Unit​.transform(UnitConverter)`. See `Units​.logarithm(Unit)` for an example.

Since:
  1.5
See Also:
  - `Units​.converter(Number, Number)`
  - `Units​.logarithm(Unit)`
  - Serialized Form

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractConverter()`
  Creates a new converter.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `UnitConverter`
  `concatenate(UnitConverter before)`
  Concatenates this converter with another converter.
  `Number`
  `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.
  `List<UnitConverter>`
  `getConversionSteps()`
  Returns the steps of fundamental converters making up this converter.
  `boolean`
  `isIdentity()`
  Returns `true` if `UnitConverter​.convert(double)` returns given values unchanged.
  `boolean`
  `isLinear()`
  Deprecated.
  This method is badly named, but we can't change since it is defined by JSR-385.

  ### Methods inherited from class Object

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

  ### Methods inherited from interface UnitConverter

  `convert, inverse`

- ## Constructor Details

  - ### AbstractConverter

    protected 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 `UnitConverter`
    Returns:
      whether this converter performs no operation.

  - ### isLinear

    @Deprecated public boolean isLinear()
    Deprecated.
    This method is badly named, but we can't change since it is defined by JSR-385.
    Indicates if this converter is linear in JSR-385 sense (not the usual mathematical sense). This is `true` if this converter contains a scale but no offset.
    Specified by:
      `isLinear` in interface `UnitConverter`
    Returns:
      whether this converter contains an offset.

  - ### 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 `UnitConverter`
    Parameters:
      `value` - the value to convert.
    Returns:
      the converted value.

  - ### derivative

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

  - ### concatenate

    public UnitConverter concatenate(UnitConverter before)
    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 `UnitConverter`
    Parameters:
      `before` - the converter to concatenate before this converter.
    Returns:
      a conversion which applies `before` first, then `this`.

  - ### getConversionSteps

    public List<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 `UnitConverter`
    Returns:
      list of steps in the unit conversion represented by this instance.