Package org.apache.sis.measure
Class IdentityConverter
java.lang.Object
org.apache.sis.measure.AbstractConverter
org.apache.sis.measure.IdentityConverter
- All Implemented Interfaces:
Serializable
,javax.measure.UnitConverter
,LenientComparable
Linear converter with a scale factor of 1 and an offset of 0. We define a class for this special case
instead of using the more generic
LinearConverter
class because we want to avoid performing
any arithmetic operation in the convert(double)
method, in order to preserve negative zero:
When the value is used in a map projection parameter, its sign can have implications in the chain of
concatenated transforms. The final result is numerically equivalent, but intermediate steps may differ
depending on the parameter sign.- Since:
- 1.0
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final IdentityConverter
The identity linear converter.private static final long
For cross-version compatibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavax.measure.UnitConverter
concatenate
(javax.measure.UnitConverter c) Concatenates this converter with another converter.double
convert
(double value) Returns the value unchanged, with a check against null values for consistency withLinearConverter.convert(Number)
.double
derivative
(double value) Returns the derivative of the conversion function at the given value, orNaN
if unknown.boolean
Compares this converter with the given object for equality.boolean
equals
(Object other, ComparisonMode mode) Compares this converter with the given object for equality, optionally ignoring rounding errors.int
hashCode()
Returns a hash code value for this unit converter.javax.measure.UnitConverter
inverse()
boolean
Returnstrue
ifUnitConverter.convert(double)
returns given values unchanged.boolean
isLinear()
Straight forward implementation.toString()
Methods inherited from class org.apache.sis.measure.AbstractConverter
coefficients, derivative, doubleValue, epsilonEquals, getConversionSteps, scale
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
INSTANCE
The identity linear converter.
-
-
Constructor Details
-
IdentityConverter
private IdentityConverter()ForINSTANCE
only.
-
-
Method Details
-
isLinear
public boolean isLinear()Straight forward implementation.- Specified by:
isLinear
in interfacejavax.measure.UnitConverter
- Overrides:
isLinear
in classAbstractConverter
-
isIdentity
public boolean isIdentity()Description copied from class:AbstractConverter
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
- Overrides:
isIdentity
in classAbstractConverter
-
inverse
public javax.measure.UnitConverter inverse()- Specified by:
inverse
in interfacejavax.measure.UnitConverter
-
convert
public double convert(double value) - Specified by:
convert
in interfacejavax.measure.UnitConverter
-
derivative
public double derivative(double value) Description copied from class:AbstractConverter
Returns the derivative of the conversion function at the given value, orNaN
if unknown.- Specified by:
derivative
in classAbstractConverter
- Parameters:
value
- the point at which to compute the derivative. Ignored (can beDouble.NaN
) if the conversion is linear.
-
concatenate
public javax.measure.UnitConverter concatenate(javax.measure.UnitConverter c) Description copied from class:AbstractConverter
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
- Overrides:
concatenate
in classAbstractConverter
-
toString
-
convert
Returns the value unchanged, with a check against null values for consistency withLinearConverter.convert(Number)
.- Specified by:
convert
in interfacejavax.measure.UnitConverter
- Overrides:
convert
in classAbstractConverter
-
hashCode
public int hashCode()Returns a hash code value for this unit converter. -
equals
Compares this converter with the given object for equality. This method may returntrue
only ifObject
is an instance ofIdentityConverter
orLinearConverter
. We apply this restriction in order to be symmetric with those cases, i.e.A.equals(B)
=B.equals(A)
.- Specified by:
equals
in interfaceLenientComparable
- Overrides:
equals
in classObject
- Parameters:
other
- the object to compare tothis
.- Returns:
true
if both objects are strictly equal.- See Also:
-
equals
Compares this converter with the given object for equality, optionally ignoring rounding errors.- Specified by:
equals
in interfaceLenientComparable
- Parameters:
other
- the object to compare tothis
.mode
- the strictness level of the comparison.- Returns:
true
if both objects are equal according the given comparison mode.- See Also:
-