Class AbstractConverter
Object
AbstractConverter
- All Implemented Interfaces:
Serializable,UnitConverter
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconcatenate(UnitConverter before) Concatenates this converter with another converter.Performs a unit conversion on the given number.abstract doublederivative(double value) Returns the derivative of the conversion function at the given value, orNaNif unknown.Returns the steps of fundamental converters making up this converter.booleanReturnstrueifUnitConverter.convert(double)returns given values unchanged.booleanIndicates if this converter is linear in JSR-385 sense (not the usual mathematical sense).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface UnitConverter
convert, inverse
-
Constructor Details
-
AbstractConverter
protected AbstractConverter()Creates a new converter.
-
-
Method Details
-
isIdentity
public boolean isIdentity()ReturnstrueifUnitConverter.convert(double)returns given values unchanged. The default implementation returnsfalsefor convenience of non-linear conversions. Subclasses should override if their conversions may be identity.- Specified by:
isIdentityin interfaceUnitConverter
-
isLinear
public boolean isLinear()Indicates if this converter is linear in JSR-385 sense (not the usual mathematical sense). The default implementation returnsfalsefor convenience of non-linear conversions. Subclasses should override if their conversions may be identity.- Specified by:
isLinearin interfaceUnitConverter
-
convert
Performs a unit conversion on the given number. The default implementation delegates to the version working ondoubleprimitive type, so it may not provide the accuracy normally required by this method contract. Linear conversions should override this method.- Specified by:
convertin interfaceUnitConverter
-
derivative
public abstract double derivative(double value) Returns the derivative of the conversion function at the given value, orNaNif unknown.- Parameters:
value- the point at which to compute the derivative. Ignored (can beDouble.NaN) if the conversion is linear.
-
concatenate
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:
concatenatein interfaceUnitConverter- Parameters:
before- the converter to concatenate before this converter.- Returns:
- a conversion which applies
beforefirst, thenthis.
-
getConversionSteps
Returns the steps of fundamental converters making up this converter. The default implementation returns onlythison the assumption that this conversion is not a concatenation of other converters. Subclasses should override if this assumption does not hold.- Specified by:
getConversionStepsin interfaceUnitConverter- Returns:
- list of steps in the unit conversion represented by this instance.
-