Package tech.units.indriya.function
Class RationalConverter
- java.lang.Object
-
- tech.units.indriya.AbstractConverter
-
- tech.units.indriya.function.RationalConverter
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<javax.measure.UnitConverter>,java.util.function.DoubleSupplier,java.util.function.Supplier<java.lang.Double>,javax.measure.UnitConverter,tech.uom.lib.common.function.ValueSupplier<java.lang.Double>
public final class RationalConverter extends AbstractConverter implements tech.uom.lib.common.function.ValueSupplier<java.lang.Double>, java.util.function.Supplier<java.lang.Double>, java.util.function.DoubleSupplier
This class represents a converter multiplying numeric values by an exact scaling factor (represented as the quotient of two
BigIntegernumbers).- Since:
- 1.0
- Version:
- 1.0, Oct 11, 2016
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class tech.units.indriya.AbstractConverter
AbstractConverter.Pair
-
-
Field Summary
Fields Modifier and Type Field Description private java.math.BigIntegerdividendHolds the converter dividend.private java.math.BigIntegerdivisorHolds the converter divisor (always positive).private static longserialVersionUID-
Fields inherited from class tech.units.indriya.AbstractConverter
conversionSteps, IDENTITY
-
-
Constructor Summary
Constructors Constructor Description RationalConverter(long dividend, long divisor)Convenience method equivalent tonew RationalConverter(BigInteger.valueOf(dividend), BigInteger.valueOf(divisor))RationalConverter(java.math.BigInteger dividend, java.math.BigInteger divisor)Creates a rational converter with the specified dividend and divisor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(javax.measure.UnitConverter o)private AbstractConvertercomposeSameType(RationalConverter that)doubleconvertWhenNotIdentity(double value)Non-APIjava.math.BigDecimalconvertWhenNotIdentity(java.math.BigDecimal value, java.math.MathContext ctx)Non-APIprotected java.lang.NumberconvertWhenNotIdentity(java.math.BigInteger value, java.math.MathContext ctx)Non-APIbooleanequals(java.lang.Object obj)java.lang.Doubleget()doublegetAsDouble()java.math.BigIntegergetDividend()Returns the integer dividend for this rational converter.java.math.BigIntegergetDivisor()Returns the integer (positive) divisor for this rational converter.java.lang.DoublegetValue()inthashCode()RationalConverterinverseWhenNotIdentity()Non-APIbooleanisIdentity()booleanisLinear()protected booleanisSimpleCompositionWith(AbstractConverter that)Non-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(java.math.BigInteger dividend, java.math.BigInteger divisor)Convenience method equivalent tonew RationalConverter(dividend, divisor)protected AbstractConvertersimpleCompose(AbstractConverter that)Non-API Guarded byAbstractConverter.isSimpleCompositionWith(AbstractConverter)private static doubletoDouble(java.math.BigInteger integer)java.lang.StringtransformationLiteral()Non-API-
Methods inherited from class tech.units.indriya.AbstractConverter
concatenate, convert, convert, getConversionSteps, inverse, of, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
dividend
private final java.math.BigInteger dividend
Holds the converter dividend.
-
divisor
private final java.math.BigInteger divisor
Holds the converter divisor (always positive).
-
-
Constructor Detail
-
RationalConverter
public RationalConverter(java.math.BigInteger dividend, java.math.BigInteger divisor)Creates a rational converter with the specified dividend and divisor.- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
java.lang.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:
java.lang.IllegalArgumentException- ifdivisor <= 0java.lang.IllegalArgumentException- ifdividend == divisor
-
-
Method Detail
-
of
public static RationalConverter of(java.math.BigInteger dividend, java.math.BigInteger divisor)
Convenience method equivalent tonew RationalConverter(dividend, divisor)- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
java.lang.IllegalArgumentException- ifdivisor <= 0java.lang.IllegalArgumentException- ifdividend == divisor
-
of
public static RationalConverter of(long dividend, long divisor)
Convenience method equivalent tonew RationalConverter(dividend, divisor)- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
java.lang.IllegalArgumentException- ifdivisor <= 0java.lang.IllegalArgumentException- ifdividend == divisor
-
of
public static RationalConverter of(double dividend, double divisor)
Convenience method equivalent tonew RationalConverter(BigDecimal.valueOf(dividend).toBigInteger(), BigDecimal.valueOf(divisor).toBigInteger())- Parameters:
dividend- the dividend.divisor- the positive divisor.- Throws:
java.lang.IllegalArgumentException- ifdivisor <= 0java.lang.IllegalArgumentException- ifdividend == divisor
-
getDividend
public java.math.BigInteger getDividend()
Returns the integer dividend for this rational converter.- Returns:
- this converter dividend.
-
getDivisor
public java.math.BigInteger 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- Returns:
- transformed value
-
toDouble
private static double toDouble(java.math.BigInteger integer)
-
convertWhenNotIdentity
protected java.lang.Number convertWhenNotIdentity(java.math.BigInteger value, java.math.MathContext ctx)Description copied from class:AbstractConverterNon-API- Overrides:
convertWhenNotIdentityin classAbstractConverter- Returns:
- transformed value (most likely a BigInteger or BigDecimal)
-
convertWhenNotIdentity
public java.math.BigDecimal convertWhenNotIdentity(java.math.BigDecimal value, java.math.MathContext ctx) throws java.lang.ArithmeticExceptionDescription copied from class:AbstractConverterNon-API- Specified by:
convertWhenNotIdentityin classAbstractConverter- Returns:
- transformed value
- Throws:
java.lang.ArithmeticException
-
isIdentity
public boolean isIdentity()
- Specified by:
isIdentityin interfacejavax.measure.UnitConverter
-
isSimpleCompositionWith
protected boolean isSimpleCompositionWith(AbstractConverter that)
Description copied from class:AbstractConverterNon-API Guard forAbstractConverter.simpleCompose(AbstractConverter)- Specified by:
isSimpleCompositionWithin classAbstractConverter- Returns:
- whether or not a 'simple' composition of transformations is possible
-
simpleCompose
protected AbstractConverter simpleCompose(AbstractConverter that)
Description copied from class:AbstractConverterNon-API Guarded byAbstractConverter.isSimpleCompositionWith(AbstractConverter)- Overrides:
simpleComposein classAbstractConverter- Returns:
- a new AbstractConverter that adds no additional conversion step
-
inverseWhenNotIdentity
public RationalConverter 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
public final java.lang.String 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
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin classAbstractConverter
-
hashCode
public int hashCode()
- Specified by:
hashCodein classAbstractConverter
-
isLinear
public boolean isLinear()
- Specified by:
isLinearin interfacejavax.measure.UnitConverter
-
getValue
public java.lang.Double getValue()
- Specified by:
getValuein interfacetech.uom.lib.common.function.ValueSupplier<java.lang.Double>
-
getAsDouble
public double getAsDouble()
- Specified by:
getAsDoublein interfacejava.util.function.DoubleSupplier
-
get
public java.lang.Double get()
- Specified by:
getin interfacejava.util.function.Supplier<java.lang.Double>
-
compareTo
public int compareTo(javax.measure.UnitConverter o)
- Specified by:
compareToin interfacejava.lang.Comparable<javax.measure.UnitConverter>
-
composeSameType
private AbstractConverter composeSameType(RationalConverter that)
-
-