Package tech.units.indriya.function
Class RationalConverter
java.lang.Object
tech.units.indriya.AbstractConverter
tech.units.indriya.function.RationalConverter
- All Implemented Interfaces:
Serializable,Comparable<javax.measure.UnitConverter>,DoubleSupplier,Supplier<Double>,javax.measure.UnitConverter,tech.uom.lib.common.function.ValueSupplier<Double>
public final class RationalConverter
extends AbstractConverter
implements tech.uom.lib.common.function.ValueSupplier<Double>, Supplier<Double>, DoubleSupplier
This class represents a converter multiplying numeric values by an exact scaling factor (represented as the quotient of two BigInteger
numbers).
- Since:
- 1.0
- Version:
- 1.0, Oct 11, 2016
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class tech.units.indriya.AbstractConverter
AbstractConverter.Pair -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BigIntegerHolds the converter dividend.private final BigIntegerHolds the converter divisor (always positive).private static final longFields inherited from class tech.units.indriya.AbstractConverter
conversionSteps, IDENTITY -
Constructor Summary
ConstructorsConstructorDescriptionRationalConverter(long dividend, long divisor) Convenience method equivalent tonew RationalConverter(BigInteger.valueOf(dividend), BigInteger.valueOf(divisor))RationalConverter(BigInteger dividend, BigInteger divisor) Creates a rational converter with the specified dividend and divisor. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(javax.measure.UnitConverter o) private AbstractConverterdoubleconvertWhenNotIdentity(double value) Non-APIconvertWhenNotIdentity(BigDecimal value, MathContext ctx) Non-APIprotected NumberconvertWhenNotIdentity(BigInteger value, MathContext ctx) Non-APIbooleanget()doubleReturns the integer dividend for this rational converter.Returns the integer (positive) divisor for this rational converter.getValue()inthashCode()Non-APIbooleanbooleanisLinear()protected booleanNon-API Guard forAbstractConverter.simpleCompose(AbstractConverter)static RationalConverterof(double dividend, double divisor) Convenience method equivalent tonew RationalConverter(BigDecimal.valueOf(dividend).toBigInteger(), BigDecimal.valueOf(divisor).toBigInteger())static RationalConverterof(long dividend, long divisor) Convenience method equivalent tonew RationalConverter(dividend, divisor)static RationalConverterof(BigInteger dividend, BigInteger divisor) Convenience method equivalent tonew RationalConverter(dividend, divisor)protected AbstractConverterNon-API Guarded byAbstractConverter.isSimpleCompositionWith(AbstractConverter)private static doubletoDouble(BigInteger integer) final StringNon-APIMethods inherited from class tech.units.indriya.AbstractConverter
concatenate, convert, convert, getConversionSteps, inverse, of, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
dividend
Holds the converter dividend. -
divisor
Holds the converter divisor (always positive).
-
-
Constructor Details
-
RationalConverter
Creates a rational converter with the specified dividend and divisor.- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
IllegalArgumentException- ifdivisor <= 0
-
RationalConverter
public RationalConverter(long dividend, long divisor) Convenience method equivalent tonew RationalConverter(BigInteger.valueOf(dividend), BigInteger.valueOf(divisor))- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
IllegalArgumentException- ifdivisor <= 0IllegalArgumentException- ifdividend == divisor
-
-
Method Details
-
of
Convenience method equivalent tonew RationalConverter(dividend, divisor)- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
IllegalArgumentException- ifdivisor <= 0IllegalArgumentException- ifdividend == divisor
-
of
Convenience method equivalent tonew RationalConverter(dividend, divisor)- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
IllegalArgumentException- ifdivisor <= 0IllegalArgumentException- ifdividend == divisor
-
of
Convenience method equivalent tonew RationalConverter(BigDecimal.valueOf(dividend).toBigInteger(), BigDecimal.valueOf(divisor).toBigInteger())- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
IllegalArgumentException- ifdivisor <= 0IllegalArgumentException- ifdividend == divisor
-
getDividend
Returns the integer dividend for this rational converter.- Returns:
- this converter dividend.
-
getDivisor
Returns the integer (positive) divisor for this rational converter.- Returns:
- this converter divisor.
-
convertWhenNotIdentity
public double convertWhenNotIdentity(double value) Description copied from class:AbstractConverterNon-API- Specified by:
convertWhenNotIdentityin classAbstractConverter- Parameters:
value-- Returns:
- transformed value
-
toDouble
-
convertWhenNotIdentity
Description copied from class:AbstractConverterNon-API- Overrides:
convertWhenNotIdentityin classAbstractConverter- Parameters:
value-ctx-- Returns:
- transformed value (most likely a BigInteger or BigDecimal)
-
convertWhenNotIdentity
public BigDecimal convertWhenNotIdentity(BigDecimal value, MathContext ctx) throws ArithmeticException Description copied from class:AbstractConverterNon-API- Specified by:
convertWhenNotIdentityin classAbstractConverter- Parameters:
value-ctx-- Returns:
- transformed value
- Throws:
ArithmeticException
-
isIdentity
public boolean isIdentity()- Specified by:
isIdentityin interfacejavax.measure.UnitConverter
-
isSimpleCompositionWith
Description copied from class:AbstractConverterNon-API Guard forAbstractConverter.simpleCompose(AbstractConverter)- Specified by:
isSimpleCompositionWithin classAbstractConverter- Parameters:
that-- Returns:
- whether or not a 'simple' composition of transformations is possible
-
simpleCompose
Description copied from class:AbstractConverterNon-API Guarded byAbstractConverter.isSimpleCompositionWith(AbstractConverter)- Overrides:
simpleComposein classAbstractConverter- Parameters:
that-- Returns:
- a new AbstractConverter that adds no additional conversion step
-
inverseWhenNotIdentity
Description copied from class:AbstractConverterNon-APIReturns an AbstractConverter that represents the inverse transformation of this converter, for cases where the transformation is not the identity transformation.
- Specified by:
inverseWhenNotIdentityin classAbstractConverter- Returns:
-
transformationLiteral
Description copied from class:AbstractConverterNon-APIReturns a String describing the transformation that is represented by this converter. Contributes to converter's
toStringmethod. If null or emptytoStringoutput becomes simplified.- Specified by:
transformationLiteralin classAbstractConverter- Returns:
-
equals
- Specified by:
equalsin classAbstractConverter
-
hashCode
public int hashCode()- Specified by:
hashCodein classAbstractConverter
-
isLinear
public boolean isLinear()- Specified by:
isLinearin interfacejavax.measure.UnitConverter
-
getValue
- Specified by:
getValuein interfacetech.uom.lib.common.function.ValueSupplier<Double>
-
getAsDouble
public double getAsDouble()- Specified by:
getAsDoublein interfaceDoubleSupplier
-
get
-
compareTo
public int compareTo(javax.measure.UnitConverter o) - Specified by:
compareToin interfaceComparable<javax.measure.UnitConverter>
-
composeSameType
-