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 longFor 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.UnitConverterconcatenate(javax.measure.UnitConverter converter) 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.(package private) static doublederivative(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 doubleReturns the value of the given number, with special handling forFloatvalue on the assumption that the original value was written in base 10.(package private) static booleanepsilonEquals(double expected, double actual) Returnstrueif the given floating point numbers are considered equal.List<javax.measure.UnitConverter>Returns the steps of fundamental converters making up this converter.booleanReturnstrueifUnitConverter.convert(double)returns given values unchanged.booleanisLinear()Indicates if this converter is linear in JSR-363 sense (not the usual mathematical sense).(package private) static doublescale(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, waitMethods 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()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 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 returnsfalsefor convenience of non-linear conversions. Subclasses should override if their conversions may be identity.- Specified by:
isLinearin 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 ondoubleprimitive type, so it may not provide the accuracy normally required by this method contract. Linear conversions should override this method.- Specified by:
convertin interfacejavax.measure.UnitConverter
-
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.
-
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 forFloatvalue 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) Returnstrueif 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:
concatenatein interfacejavax.measure.UnitConverter
-
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 interfacejavax.measure.UnitConverter
-