Package org.apache.sis.measure
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
FieldsModifier and TypeFieldDescriptionprivate static final long
For cross-version compatibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(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.Performs a unit conversion on the given number.abstract double
derivative
(double value) Returns the derivative of the conversion function at the given value, orNaN
if unknown.(package private) static double
derivative
(javax.measure.UnitConverter converter, double value) Delegates toderivative(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 forFloat
value on the assumption that the original value was written in base 10.(package private) static boolean
epsilonEquals
(double expected, double actual) Returnstrue
if the given floating point numbers are considered equal.List<javax.measure.UnitConverter>
Returns the steps of fundamental converters making up this converter.boolean
Returnstrue
ifUnitConverter.convert(double)
returns given values unchanged.boolean
isLinear()
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 serialVersionUIDFor cross-version compatibility.- See Also:
-
-
Constructor Details
-
AbstractConverter
AbstractConverter()Creates a new converter.
-
-
Method Details
-
isIdentity
public boolean isIdentity()Returnstrue
ifUnitConverter.convert(double)
returns given values unchanged. The default implementation returnsfalse
for convenience of non-linear conversions. Subclasses should override if their conversions may be identity.- Specified by:
isIdentity
in interfacejavax.measure.UnitConverter
-
isLinear
public boolean isLinear()Indicates if this converter is linear in JSR-363 sense (not the usual mathematical sense). The default implementation returnsfalse
for convenience of non-linear conversions. Subclasses should override if their conversions may be identity.- Specified by:
isLinear
in interfacejavax.measure.UnitConverter
-
coefficients
Number[] coefficients()If the conversion can be represented by a polynomial equation, returns the coefficients of that equation. Otherwise returnsnull
. -
convert
Performs a unit conversion on the given number. The default implementation delegates to the version working ondouble
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 interfacejavax.measure.UnitConverter
-
derivative
public abstract double derivative(double value) Returns the derivative of the conversion function at the given value, orNaN
if unknown.- Parameters:
value
- the point at which to compute the derivative. Ignored (can beDouble.NaN
) if the conversion is linear.
-
derivative
static double derivative(javax.measure.UnitConverter converter, double value) Delegates toderivative(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
Returns the value of the given number, with special handling forFloat
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) Returnstrue
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 interfacejavax.measure.UnitConverter
-
getConversionSteps
Returns the steps of fundamental converters making up this converter. The default implementation returns onlythis
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 interfacejavax.measure.UnitConverter
-