Package foundation.omni
Class OmniDivisibleValue
java.lang.Object
java.lang.Number
javax.money.NumberValue
foundation.omni.OmniValue
foundation.omni.OmniDivisibleValue
- All Implemented Interfaces:
Serializable
,Comparable<javax.money.NumberValue>
Numeric Value of Divisible Omni Token
An Omni Divisible token is typically represented to the user as a decimal amount and hence
you can have a fractional number of tokens. Internally it uses the same format as an indivisible token.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MathContext
static final int
static OmniDivisibleValue
static final long
static final BigDecimal
static OmniDivisibleValue
static final long
static final BigDecimal
static OmniDivisibleValue
Fields inherited from class foundation.omni.OmniValue
MAX_WILLETTS, MIN_WILLETTS, willetts, willettsPerDivisible
-
Method Summary
Modifier and TypeMethodDescriptionConvert to aBigDecimal
value.byte
static void
checkValue
(long candidate) Make sure a long value is a valid value for OmniDivisibleValuestatic void
checkValue
(BigDecimal candidate) Make sure a BigDecimal value is a valid value for OmniDivisibleValuedouble
Return a double value.double
boolean
float
long
long
int
int
getScale()
int
intValue()
int
long
long
minus
(OmniDivisibleValue right) Return value in preferred number typestatic OmniDivisibleValue
of
(long amount) Create OmniDivisibleValue of the specified amountstatic OmniDivisibleValue
of
(BigDecimal amount) Create OmniDivisibleValue of the specified amountstatic OmniDivisibleValue
ofWilletts
(long willetts) Create OmniDivisibleValue from willetts/internal/wire formatplus
(OmniDivisibleValue right) round
(MathContext mathContext) short
Convert toString
.Convert toString
.Convert toString
.toString()
Convert toString
.Methods inherited from class foundation.omni.OmniValue
checkWillettValue, checkWillettValue, compareTo, getWilletts, hashCode, minus, multiply, numberValue, numberValueExact, of, of, of, of, of, of, ofWilletts, ofWilletts, plus
-
Field Details
-
DEFAULT_CONTEXT
-
DEFAULT_SCALE
public static final int DEFAULT_SCALE- See Also:
-
MIN_VALUE
-
MAX_VALUE
-
MIN_INT_VALUE
public static final long MIN_INT_VALUE- See Also:
-
MAX_INT_VALUE
public static final long MAX_INT_VALUE- See Also:
-
ZERO
-
MIN
-
MAX
-
-
Method Details
-
of
Create OmniDivisibleValue of the specified amount- Parameters:
amount
- Number of Omni tokens- Returns:
- OmniDivisibleValue representing amount
-
of
Create OmniDivisibleValue of the specified amount- Parameters:
amount
- Number of Omni tokens- Returns:
- OmniDivisibleValue representing amount
-
ofWilletts
Create OmniDivisibleValue from willetts/internal/wire format- Parameters:
willetts
- number of willetts- Returns:
- OmniIndivisibleValue equal to number of willetts
-
checkValue
Make sure a BigDecimal value is a valid value for OmniDivisibleValue
- Parameters:
candidate
- value to check- Throws:
ArithmeticException
- if less than minimum or greater than maximum allowed value
-
checkValue
Make sure a long value is a valid value for OmniDivisibleValue
- Parameters:
candidate
- value to check.- Throws:
ArithmeticException
- if less than minimum or greater than maximum allowed value
-
equals
-
toString
Convert toString
. Uses standard JVMtoString()
formats. ForOmniDivisibleValue
it is the same format asBigDecimal
(this means"0E-8"
forZERO
.) ForOmniIndivisibleValue
it is the same format asLong
. -
toPlainString
Convert toString
. ForOmniDivisibleValue
the same format asBigDecimal.toPlainString()
. ForOmniIndivisibleValue
it is the same asOmniIndivisibleValue.toString()
.- Specified by:
toPlainString
in classOmniValue
- Returns:
- Number as a string
-
toJsonFormattedString
Convert toString
. The required format for OmniValues in JSON. ForOmniDivisibleValue
there is always at least one place after the decimal point (e.g."0.0"
). This allows humans and parsers to easily tellOmniDivisibleValue
s fromOmniIndivisibleValue
s. Note: The'.'
separator is always used regardless of the currentLocale
.- Specified by:
toJsonFormattedString
in classOmniValue
- Returns:
- Number as a string
-
toFormattedString
Convert toString
. A human-readable format using locale-specific place-separators.- Specified by:
toFormattedString
in classOmniValue
- Returns:
- Number as a string
-
getPropertyType
- Specified by:
getPropertyType
in classOmniValue
- Returns:
- property type
-
getNumberType
- Specified by:
getNumberType
in classOmniValue
-
numberValue
Return value in preferred number type- Specified by:
numberValue
in classOmniValue
- Returns:
- value as represented in best/preferred number type
-
getPrecision
public int getPrecision()- Overrides:
getPrecision
in classOmniValue
-
getScale
public int getScale() -
intValueExact
public int intValueExact()- Overrides:
intValueExact
in classOmniValue
-
longValueExact
public long longValueExact()- Overrides:
longValueExact
in classOmniValue
-
doubleValueExact
public double doubleValueExact()- Specified by:
doubleValueExact
in classOmniValue
-
round
- Specified by:
round
in classjavax.money.NumberValue
-
getAmountFractionNumerator
public long getAmountFractionNumerator()- Overrides:
getAmountFractionNumerator
in classOmniValue
-
getAmountFractionDenominator
public long getAmountFractionDenominator()- Overrides:
getAmountFractionDenominator
in classOmniValue
-
byteValue
public byte byteValue() -
shortValue
public short shortValue()- Overrides:
shortValue
in classOmniValue
-
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Overrides:
floatValue
in classOmniValue
-
doubleValue
public double doubleValue()Return a double value. Warning: this will result in rounding errors. Only use this for applications like plotting data, never for anything that counts currency.- Specified by:
doubleValue
in classOmniValue
- Returns:
- The value rounded to the nearest
double
.
-
bigDecimalValue
Convert to aBigDecimal
value. This will be lossless. ForOmniIndivisibleValue
theBigDecimal
value will be an integer, of course.- Specified by:
bigDecimalValue
in classOmniValue
- Returns:
- the value
-
plus
-
minus
-