Package javax.measure.converter
Class MultiplyConverter
java.lang.Object
javax.measure.converter.UnitConverter
javax.measure.converter.MultiplyConverter
- All Implemented Interfaces:
Serializable
This class represents a converter multiplying numeric values by a
constant scaling factor (approximated as a double
).
For exact scaling conversions RationalConverter
is preferred.
Instances of this class are immutable.
- See Also:
-
Field Summary
Fields inherited from class javax.measure.converter.UnitConverter
IDENTITY
-
Constructor Summary
ConstructorDescriptionMultiplyConverter
(double factor) Creates a multiply converter with the specified scale factor. -
Method Summary
Modifier and TypeMethodDescriptionconcatenate
(UnitConverter converter) Concatenates this converter with another converter.double
convert
(double amount) Converts a double value.double
Returns the scale factor.inverse()
Returns the inverse of this converter.boolean
isLinear()
Indicates if this converter is linear.Methods inherited from class javax.measure.converter.UnitConverter
equals, hashCode
-
Constructor Details
-
MultiplyConverter
public MultiplyConverter(double factor) Creates a multiply converter with the specified scale factor.- Parameters:
factor
- the scale factor.- Throws:
IllegalArgumentException
- if offset is one (or close to one).
-
-
Method Details
-
getFactor
public double getFactor()Returns the scale factor.- Returns:
- the scale factor.
-
inverse
Description copied from class:UnitConverter
Returns the inverse of this converter. Ifx
is a valid value, thenx == inverse().convert(convert(x))
to within the accuracy of computer arithmetic.- Specified by:
inverse
in classUnitConverter
- Returns:
- the inverse of this converter.
-
convert
public double convert(double amount) Description copied from class:UnitConverter
Converts a double value.- Specified by:
convert
in classUnitConverter
- Parameters:
amount
- the numeric value to convert.- Returns:
- the converted numeric value.
-
isLinear
public boolean isLinear()Description copied from class:UnitConverter
Indicates if this converter is linear. A converter is linear ifconvert(u + v) == convert(u) + convert(v)
andconvert(r * u) == r * convert(u)
. For linear converters the following property always hold:[code] y1 = c1.convert(x1); y2 = c2.convert(x2); then y1*y2 = c1.concatenate(c2).convert(x1*x2)[/code]- Specified by:
isLinear
in classUnitConverter
- Returns:
true
if this converter is linear;false
otherwise.
-
concatenate
Description copied from class:UnitConverter
Concatenates this converter with another converter. The resulting converter is equivalent to first converting by the specified converter, and then converting by this converter.Note: Implementations must ensure that the
UnitConverter.IDENTITY
instance is returned if the resulting converter is an identity converter.- Overrides:
concatenate
in classUnitConverter
- Parameters:
converter
- the other converter.- Returns:
- the concatenation of this converter with the other converter.
-