Package javax.measure.converter
Class RationalConverter
java.lang.Object
javax.measure.converter.UnitConverter
javax.measure.converter.RationalConverter
- All Implemented Interfaces:
Serializable
This class represents a converter multiplying numeric values by an
exact scaling factor (represented as the quotient of two
long numbers).
Instances of this class are immutable.
- See Also:
-
Field Summary
Fields inherited from class javax.measure.converter.UnitConverter
IDENTITY -
Constructor Summary
ConstructorsConstructorDescriptionRationalConverter(long dividend, long divisor) Creates a rational converter with the specified dividend and divisor. -
Method Summary
Modifier and TypeMethodDescriptionconcatenate(UnitConverter converter) Concatenates this converter with another converter.doubleconvert(double amount) Converts a double value.longReturns the dividend for this rational converter.longReturns the positive divisor for this rational converter.inverse()Returns the inverse of this converter.booleanisLinear()Indicates if this converter is linear.Methods inherited from class javax.measure.converter.UnitConverter
equals, hashCode
-
Constructor Details
-
RationalConverter
public RationalConverter(long dividend, long divisor) Creates a rational converter with the specified dividend and divisor.- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
IllegalArgumentException- ifdivisor < 0IllegalArgumentException- ifdividend == divisor
-
-
Method Details
-
getDividend
public long getDividend()Returns the dividend for this rational converter.- Returns:
- this converter dividend.
-
getDivisor
public long getDivisor()Returns the positive divisor for this rational converter.- Returns:
- this converter divisor.
-
inverse
Description copied from class:UnitConverterReturns the inverse of this converter. Ifxis a valid value, thenx == inverse().convert(convert(x))to within the accuracy of computer arithmetic.- Specified by:
inversein classUnitConverter- Returns:
- the inverse of this converter.
-
convert
public double convert(double amount) Description copied from class:UnitConverterConverts a double value.- Specified by:
convertin classUnitConverter- Parameters:
amount- the numeric value to convert.- Returns:
- the converted numeric value.
-
isLinear
public boolean isLinear()Description copied from class:UnitConverterIndicates 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:
isLinearin classUnitConverter- Returns:
trueif this converter is linear;falseotherwise.
-
concatenate
Description copied from class:UnitConverterConcatenates 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.IDENTITYinstance is returned if the resulting converter is an identity converter.- Overrides:
concatenatein classUnitConverter- Parameters:
converter- the other converter.- Returns:
- the concatenation of this converter with the other converter.
-