public final class RationalConverter extends AbstractConverter implements tec.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).
AbstractConverter.Pair
IDENTITY, PI
Constructor and Description |
---|
RationalConverter(BigInteger dividend,
BigInteger divisor)
Creates a rational converter with the specified dividend and divisor.
|
RationalConverter(long dividend,
long divisor)
Convenience method equivalent to
new RationalConverter(BigInteger.valueOf(dividend), BigInteger.valueOf(divisor)) |
Modifier and Type | Method and Description |
---|---|
javax.measure.UnitConverter |
concatenate(javax.measure.UnitConverter converter) |
BigDecimal |
convert(BigDecimal value,
MathContext ctx) |
double |
convert(double value) |
boolean |
equals(Object obj) |
Double |
get() |
double |
getAsDouble() |
BigInteger |
getDividend()
Returns the integer dividend for this rational converter.
|
BigInteger |
getDivisor()
Returns the integer (positive) divisor for this rational converter.
|
Double |
getValue() |
int |
hashCode() |
RationalConverter |
inverse() |
boolean |
isLinear() |
static RationalConverter |
of(BigInteger dividend,
BigInteger divisor)
Convenience method equivalent to
new RationalConverter(dividend, divisor) |
static RationalConverter |
of(double dividend,
double divisor)
Convenience method equivalent to
new RationalConverter(BigDecimal.valueOf(dividend).toBigInteger(),
BigDecimal.valueOf(divisor).toBigInteger()) |
static RationalConverter |
of(long dividend,
long divisor)
Convenience method equivalent to
new RationalConverter(dividend, divisor) |
String |
toString() |
concatenate, convert, getConversionSteps, isIdentity
public RationalConverter(BigInteger dividend, BigInteger divisor)
dividend
- the dividend.divisor
- the positive divisor.IllegalArgumentException
- if divisor <= 0
IllegalArgumentException
- if dividend == divisor
public RationalConverter(long dividend, long divisor)
new RationalConverter(BigInteger.valueOf(dividend), BigInteger.valueOf(divisor))
dividend
- the dividend.divisor
- the positive divisor.IllegalArgumentException
- if divisor <= 0
IllegalArgumentException
- if dividend == divisor
public static RationalConverter of(BigInteger dividend, BigInteger divisor)
new RationalConverter(dividend, divisor)
dividend
- the dividend.divisor
- the positive divisor.IllegalArgumentException
- if divisor <= 0
IllegalArgumentException
- if dividend == divisor
public static RationalConverter of(long dividend, long divisor)
new RationalConverter(dividend, divisor)
dividend
- the dividend.divisor
- the positive divisor.IllegalArgumentException
- if divisor <= 0
IllegalArgumentException
- if dividend == divisor
public static RationalConverter of(double dividend, double divisor)
new RationalConverter(BigDecimal.valueOf(dividend).toBigInteger(),
BigDecimal.valueOf(divisor).toBigInteger())
dividend
- the dividend.divisor
- the positive divisor.IllegalArgumentException
- if divisor <= 0
IllegalArgumentException
- if dividend == divisor
public BigInteger getDividend()
public BigInteger getDivisor()
public double convert(double value)
convert
in interface javax.measure.UnitConverter
convert
in class AbstractConverter
public BigDecimal convert(BigDecimal value, MathContext ctx) throws ArithmeticException
convert
in class AbstractConverter
ArithmeticException
public javax.measure.UnitConverter concatenate(javax.measure.UnitConverter converter)
concatenate
in interface javax.measure.UnitConverter
concatenate
in class AbstractConverter
public RationalConverter inverse()
inverse
in interface javax.measure.UnitConverter
inverse
in class AbstractConverter
public boolean equals(Object obj)
equals
in class AbstractConverter
public int hashCode()
hashCode
in class AbstractConverter
public boolean isLinear()
isLinear
in interface javax.measure.UnitConverter
public Double getValue()
getValue
in interface tec.uom.lib.common.function.ValueSupplier<Double>
public double getAsDouble()
getAsDouble
in interface DoubleSupplier
Copyright © 2005–2017 Units of Measurement project. All rights reserved.