Package tech.units.indriya.function
Class AbstractConverter
- java.lang.Object
-
- tech.units.indriya.function.AbstractConverter
-
- All Implemented Interfaces:
Serializable,Comparable<UnitConverter>,UnitConverter,tech.uom.lib.common.function.Converter<Number,Number>
- Direct Known Subclasses:
AbstractConverter.Pair,AddConverter,ExpConverter,LogConverter,PowerOfIntConverter,RationalConverter
public abstract class AbstractConverter extends Object implements UnitConverter, tech.uom.lib.common.function.Converter<Number,Number>, Serializable, Comparable<UnitConverter>
The base class for our
UnitConverterimplementations.- Since:
- 1.0
- Version:
- 2.1, Mai 28, 2020
- Author:
- Jean-Marie Dautelle, Werner Keil, Andi Huber
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractConverter.PairThis class represents converters made up of two or more separate converters (in matrix notation[pair] = [left] x [right]).
-
Field Summary
Fields Modifier and Type Field Description protected List<? extends UnitConverter>conversionStepsmemorization for getConversionStepsstatic AbstractConverterIDENTITYDefault identity converter implementing AbstractConverter.static ConverterCompositionHandlerUNIT_COMPOSITION_HANDLERAllows for plug in of a custom UnitCompositionHandler.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConverter()DefaultQuantityFactory constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract booleancanReduceWith(AbstractConverter that)Non-API Guard forreduce(AbstractConverter)UnitConverterconcatenate(UnitConverter converter)doubleconvert(double value)Numberconvert(Number value)protected abstract NumberconvertWhenNotIdentity(Number value)Non-APIabstract booleanequals(Object cvtr)List<? extends UnitConverter>getConversionSteps()abstract inthashCode()AbstractConverterinverse()protected abstract AbstractConverterinverseWhenNotIdentity()Non-APIOptional<Number>linearFactor()Even though transformations may be composed of addition and multiplication, the first derivative might just be a linear function.protected AbstractConverterreduce(AbstractConverter that)Non-API Guarded bycanReduceWith(AbstractConverter)StringtoString()protected abstract StringtransformationLiteral()Non-API-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface javax.measure.UnitConverter
isIdentity, isLinear
-
-
-
-
Field Detail
-
IDENTITY
public static final AbstractConverter IDENTITY
Default identity converter implementing AbstractConverter.Note: Checking whether a UnitConverter is an identity operator should be done with
UnitConverter.isIdentity()rather than checking for object identityunitConverter == AbstractConverter.IDENTITY.
-
UNIT_COMPOSITION_HANDLER
public static ConverterCompositionHandler UNIT_COMPOSITION_HANDLER
Allows for plug in of a custom UnitCompositionHandler.
-
conversionSteps
protected List<? extends UnitConverter> conversionSteps
memorization for getConversionSteps
-
-
Constructor Detail
-
AbstractConverter
protected AbstractConverter()
DefaultQuantityFactory constructor.
-
-
Method Detail
-
transformationLiteral
protected abstract String transformationLiteral()
Non-APIReturns a String describing the transformation that is represented by this converter. Contributes to converter's
toStringmethod. If null or emptytoStringoutput becomes simplified.- Returns:
-
inverseWhenNotIdentity
protected abstract AbstractConverter inverseWhenNotIdentity()
Non-APIReturns an AbstractConverter that represents the inverse transformation of this converter, for cases where the transformation is not the identity transformation.
- Returns:
-
inverse
public final AbstractConverter inverse()
- Specified by:
inversein interfaceUnitConverter
-
canReduceWith
protected abstract boolean canReduceWith(AbstractConverter that)
Non-API Guard forreduce(AbstractConverter)- Parameters:
that-- Returns:
- whether or not a composition with given
thatis possible, such that no additional conversion steps are required, with respect to the steps already in place by this converter
-
reduce
protected AbstractConverter reduce(AbstractConverter that)
Non-API Guarded bycanReduceWith(AbstractConverter)- Parameters:
that-- Returns:
- a new AbstractConverter that adds no additional conversion steps, with respect to the steps already in place by this converter
-
concatenate
public final UnitConverter concatenate(UnitConverter converter)
- Specified by:
concatenatein interfaceUnitConverter
-
getConversionSteps
public final List<? extends UnitConverter> getConversionSteps()
- Specified by:
getConversionStepsin interfaceUnitConverter
-
convertWhenNotIdentity
protected abstract Number convertWhenNotIdentity(Number value)
Non-API- Parameters:
value-- Returns:
- transformed value
-
convert
public final double convert(double value)
- Specified by:
convertin interfaceUnitConverter
-
convert
public final Number convert(Number value)
- Specified by:
convertin interfacetech.uom.lib.common.function.Converter<Number,Number>- Specified by:
convertin interfaceUnitConverter- Throws:
IllegalArgumentException- if the value isnull.
-
linearFactor
public Optional<Number> linearFactor()
Even though transformations may be composed of addition and multiplication, the first derivative might just be a linear function. This is strictly required for Quantities that are expressed with RELATIVE scope. Eg. Δ2°C or Δ2°F. Otherwise such deltas cannot be converted to ABSOLUTE scope without additional information.- Returns:
- optionally the linear factor of this transformation's first derivative, based on whether this transformation allows for RELATIVE scaled Quantities
-
-