Class OceanusRate
java.lang.Object
io.github.tonywasher.joceanus.oceanus.decimal.OceanusDecimal
io.github.tonywasher.joceanus.oceanus.decimal.OceanusRate
- All Implemented Interfaces:
Comparable<OceanusDecimal>
Represents a Rate object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intStandard number of decimals for Rate.static final OceanusRateOne hundred percent.Fields inherited from class io.github.tonywasher.joceanus.oceanus.decimal.OceanusDecimal
BYTE_LEN, MAX_DECIMALS, RADIX_TEN -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstruct a new Rate.OceanusRate(byte[] pBuffer) Create the rate from a byte array.OceanusRate(OceanusDecimal pFirst, OceanusDecimal pSecond) Construct a new Ratio by the ratio between two decimals.OceanusRate(OceanusRate pRate) Construct a new Rate by copying another rate.OceanusRate(OceanusRatio pRatio) Construct a new Rate from a ratio.OceanusRate(String pSource) Constructor for rate from a decimal string. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddValue(OceanusDecimal pValue) Add a Decimal to the value.Obtain inverse ratio of this rate (i.e. 100%/this rate).Obtain remaining rate of this rate (i.e. 100% - this rate).static OceanusRategetTenthPermille(long pValue) Construct a new Rate by setting the value explicitly.static OceanusRategetWholePercentage(long pValue) Construct a new Rate by setting the value explicitly.static OceanusRategetWholePermille(long pValue) Construct a new Rate by setting the value explicitly.voidsubtractValue(OceanusDecimal pValue) Subtract a Decimal from the value.Methods inherited from class io.github.tonywasher.joceanus.oceanus.decimal.OceanusDecimal
add, adjustDecimals, adjustToScale, byteValue, byteValueExact, calculateProduct, calculateQuotient, calculateSafeQuotient, checkFractionalZero, compareTo, divide, divide, divideToIntegralValue, doubleValue, equals, floatValue, getFactor, hashCode, intValue, intValueExact, isNonZero, isPositive, isZero, longValue, longValueExact, max, min, movePointLeft, movePointRight, multiply, multiply, negate, recordScale, reduceScale, remainder, scale, setValue, setZero, shortValue, shortValueExact, signum, subtract, toBigDecimal, toBigInteger, toBigIntegerExact, toBytes, toString, unscaledValue
-
Field Details
-
NUM_DECIMALS
protected static final int NUM_DECIMALSStandard number of decimals for Rate.- See Also:
-
RATE_ONEHUNDREDPERCENT
One hundred percent.
-
-
Constructor Details
-
OceanusRate
protected OceanusRate()Construct a new Rate. -
OceanusRate
Construct a new Rate by copying another rate.- Parameters:
pRate- the Rate to copy
-
OceanusRate
Construct a new Ratio by the ratio between two decimals.- Parameters:
pFirst- the first decimalpSecond- the second decimal
-
OceanusRate
Construct a new Rate from a ratio.- Parameters:
pRatio- the Ratio
-
OceanusRate
Constructor for rate from a decimal string.- Parameters:
pSource- The source decimal string- Throws:
IllegalArgumentException- on invalidly formatted argument
-
OceanusRate
public OceanusRate(byte[] pBuffer) Create the rate from a byte array.- Parameters:
pBuffer- the buffer
-
-
Method Details
-
getWholePercentage
Construct a new Rate by setting the value explicitly.- Parameters:
pValue- the unscaled value of a whole percentage (e.g. 2 = 2%)- Returns:
- the new Rate
-
getWholePermille
Construct a new Rate by setting the value explicitly.- Parameters:
pValue- the unscaled value of a whole percentage (e.g. 25 = 2.5%)- Returns:
- the new Rate
-
getTenthPermille
Construct a new Rate by setting the value explicitly.- Parameters:
pValue- the unscaled value of a whole percentage (e.g. 25 = 0.25%)- Returns:
- the new Rate
-
getRemainingRate
Obtain remaining rate of this rate (i.e. 100% - this rate).- Returns:
- the remaining rate
-
getInverseRatio
Obtain inverse ratio of this rate (i.e. 100%/this rate).- Returns:
- the inverse ratio
-
addValue
Description copied from class:OceanusDecimalAdd a Decimal to the value. The value of this Decimal is updated and the scale is maintained.- Overrides:
addValuein classOceanusDecimal- Parameters:
pValue- The Decimal to add to this one.
-
subtractValue
Description copied from class:OceanusDecimalSubtract a Decimal from the value. The value of this Decimal is updated and the scale is maintained.- Overrides:
subtractValuein classOceanusDecimal- Parameters:
pValue- The decimal to subtract from this one.
-