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 BigInteger
Holds the converter dividend.private final BigInteger
Holds the converter divisor (always positive).private static final long
Fields 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 TypeMethodDescriptionint
compareTo
(javax.measure.UnitConverter o) private AbstractConverter
double
convertWhenNotIdentity
(double value) Non-APIconvertWhenNotIdentity
(BigDecimal value, MathContext ctx) Non-APIprotected Number
convertWhenNotIdentity
(BigInteger value, MathContext ctx) Non-APIboolean
get()
double
Returns the integer dividend for this rational converter.Returns the integer (positive) divisor for this rational converter.getValue()
int
hashCode()
Non-APIboolean
boolean
isLinear()
protected boolean
Non-API Guard forAbstractConverter.simpleCompose(AbstractConverter)
static RationalConverter
of
(double dividend, double divisor) Convenience method equivalent tonew RationalConverter(BigDecimal.valueOf(dividend).toBigInteger(), BigDecimal.valueOf(divisor).toBigInteger())
static RationalConverter
of
(long dividend, long divisor) Convenience method equivalent tonew RationalConverter(dividend, divisor)
static RationalConverter
of
(BigInteger dividend, BigInteger divisor) Convenience method equivalent tonew RationalConverter(dividend, divisor)
protected AbstractConverter
Non-API Guarded byAbstractConverter.isSimpleCompositionWith(AbstractConverter)
private static double
toDouble
(BigInteger integer) final String
Non-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 <= 0
IllegalArgumentException
- ifdividend == divisor
-
-
Method Details
-
of
Convenience method equivalent tonew RationalConverter(dividend, divisor)
- Parameters:
dividend
- the dividend.divisor
- the positive divisor.- Throws:
IllegalArgumentException
- ifdivisor <= 0
IllegalArgumentException
- ifdividend == divisor
-
of
Convenience method equivalent tonew RationalConverter(dividend, divisor)
- Parameters:
dividend
- the dividend.divisor
- the positive divisor.- Throws:
IllegalArgumentException
- ifdivisor <= 0
IllegalArgumentException
- 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 <= 0
IllegalArgumentException
- 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:AbstractConverter
Non-API- Specified by:
convertWhenNotIdentity
in classAbstractConverter
- Returns:
- transformed value
-
toDouble
-
convertWhenNotIdentity
Description copied from class:AbstractConverter
Non-API- Overrides:
convertWhenNotIdentity
in classAbstractConverter
- Returns:
- transformed value (most likely a BigInteger or BigDecimal)
-
convertWhenNotIdentity
public BigDecimal convertWhenNotIdentity(BigDecimal value, MathContext ctx) throws ArithmeticException Description copied from class:AbstractConverter
Non-API- Specified by:
convertWhenNotIdentity
in classAbstractConverter
- Returns:
- transformed value
- Throws:
ArithmeticException
-
isIdentity
public boolean isIdentity()- Specified by:
isIdentity
in interfacejavax.measure.UnitConverter
-
isSimpleCompositionWith
Description copied from class:AbstractConverter
Non-API Guard forAbstractConverter.simpleCompose(AbstractConverter)
- Specified by:
isSimpleCompositionWith
in classAbstractConverter
- Returns:
- whether or not a 'simple' composition of transformations is possible
-
simpleCompose
Description copied from class:AbstractConverter
Non-API Guarded byAbstractConverter.isSimpleCompositionWith(AbstractConverter)
- Overrides:
simpleCompose
in classAbstractConverter
- Returns:
- a new AbstractConverter that adds no additional conversion step
-
inverseWhenNotIdentity
Description copied from class:AbstractConverter
Non-APIReturns an AbstractConverter that represents the inverse transformation of this converter, for cases where the transformation is not the identity transformation.
- Specified by:
inverseWhenNotIdentity
in classAbstractConverter
- Returns:
-
transformationLiteral
Description copied from class:AbstractConverter
Non-APIReturns a String describing the transformation that is represented by this converter. Contributes to converter's
toString
method. If null or emptytoString
output becomes simplified.- Specified by:
transformationLiteral
in classAbstractConverter
- Returns:
-
equals
- Specified by:
equals
in classAbstractConverter
-
hashCode
public int hashCode()- Specified by:
hashCode
in classAbstractConverter
-
isLinear
public boolean isLinear()- Specified by:
isLinear
in interfacejavax.measure.UnitConverter
-
getValue
- Specified by:
getValue
in interfacetech.uom.lib.common.function.ValueSupplier<Double>
-
getAsDouble
public double getAsDouble()- Specified by:
getAsDouble
in interfaceDoubleSupplier
-
get
-
compareTo
public int compareTo(javax.measure.UnitConverter o) - Specified by:
compareTo
in interfaceComparable<javax.measure.UnitConverter>
-
composeSameType
-