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 IdentityConverterThe identity linear converter.private static final longFor cross-version compatibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavax.measure.UnitConverterconcatenate(javax.measure.UnitConverter c) Concatenates this converter with another converter.doubleconvert(double value) Returns the value unchanged, with a check against null values for consistency withLinearConverter.convert(Number).doublederivative(double value) Returns the derivative of the conversion function at the given value, orNaNif unknown.booleanCompares this converter with the given object for equality.booleanequals(Object other, ComparisonMode mode) Compares this converter with the given object for equality, optionally ignoring rounding errors.inthashCode()Returns a hash code value for this unit converter.javax.measure.UnitConverterinverse()booleanReturnstrueifUnitConverter.convert(double)returns given values unchanged.booleanisLinear()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()ForINSTANCEonly.
-
-
Method Details
-
isLinear
public boolean isLinear()Straight forward implementation.- Specified by:
isLinearin interfacejavax.measure.UnitConverter- Overrides:
isLinearin classAbstractConverter
-
isIdentity
public boolean isIdentity()Description copied from class:AbstractConverterReturnstrueifUnitConverter.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- Overrides:
isIdentityin classAbstractConverter
-
inverse
public javax.measure.UnitConverter inverse()- Specified by:
inversein interfacejavax.measure.UnitConverter
-
convert
public double convert(double value) - Specified by:
convertin interfacejavax.measure.UnitConverter
-
derivative
public double derivative(double value) Description copied from class:AbstractConverterReturns the derivative of the conversion function at the given value, orNaNif unknown.- Specified by:
derivativein 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:AbstractConverterConcatenates 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- Overrides:
concatenatein classAbstractConverter
-
toString
-
convert
Returns the value unchanged, with a check against null values for consistency withLinearConverter.convert(Number).- Specified by:
convertin interfacejavax.measure.UnitConverter- Overrides:
convertin 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 returntrueonly ifObjectis an instance ofIdentityConverterorLinearConverter. We apply this restriction in order to be symmetric with those cases, i.e.A.equals(B)=B.equals(A).- Specified by:
equalsin interfaceLenientComparable- Overrides:
equalsin classObject- Parameters:
other- the object to compare tothis.- Returns:
trueif both objects are strictly equal.- See Also:
-
equals
Compares this converter with the given object for equality, optionally ignoring rounding errors.- Specified by:
equalsin interfaceLenientComparable- Parameters:
other- the object to compare tothis.mode- the strictness level of the comparison.- Returns:
trueif both objects are equal according the given comparison mode.- See Also:
-