Package foundation.omni
Class OmniIndivisibleValue
java.lang.Object
java.lang.Number
javax.money.NumberValue
foundation.omni.OmniValue
foundation.omni.OmniIndivisibleValue
- All Implemented Interfaces:
Serializable
,Comparable<javax.money.NumberValue>
Numeric Value of Indivisible Omni Token
An indivisible token is an integer number of tokens that can't be subdivided to
less than one token.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final OmniIndivisibleValue
static final BigInteger
static final long
static final OmniIndivisibleValue
static final BigInteger
static final long
static final OmniIndivisibleValue
Fields inherited from class foundation.omni.OmniValue
MAX_WILLETTS, MIN_WILLETTS, willetts, willettsPerDivisible
-
Method Summary
Modifier and TypeMethodDescriptionConvert to aBigDecimal
value.static void
checkValue
(long candidate) Make sure a BigInteger value is a valid value for OmniIndivisibleValuestatic void
checkValue
(BigInteger candidate) Make sure a BigInteger value is a valid value for OmniIndivisibleValuedouble
Return a double value.double
boolean
minus
(OmniIndivisibleValue right) Return value in preferred number typestatic OmniIndivisibleValue
of
(long amount) Create OmniDivisibleValue of the specified amountstatic OmniIndivisibleValue
of
(BigInteger amount) static OmniIndivisibleValue
ofWilletts
(long willetts) Create OmniIndivisibleValue from willetts/internal/wire formatplus
(OmniIndivisibleValue right) round
(MathContext mathContext) Convert toString
.Convert toString
.Convert toString
.toString()
Convert toString
.Methods inherited from class foundation.omni.OmniValue
byteValue, checkWillettValue, checkWillettValue, compareTo, floatValue, getAmountFractionDenominator, getAmountFractionNumerator, getPrecision, getScale, getWilletts, hashCode, intValue, intValueExact, longValue, longValueExact, minus, multiply, numberValue, numberValueExact, of, of, of, of, of, of, ofWilletts, ofWilletts, plus, shortValue
-
Field Details
-
MIN_VALUE
public static final long MIN_VALUE- See Also:
-
MAX_VALUE
public static final long MAX_VALUE- See Also:
-
MIN_BIGINT
-
MAX_BIGINT
-
ZERO
-
MIN
-
MAX
-
-
Method Details
-
of
-
of
Create OmniDivisibleValue of the specified amount- Parameters:
amount
- Number of Omni tokens- Returns:
- OmniDivisibleValue representing amount tokens
-
ofWilletts
Create OmniIndivisibleValue from willetts/internal/wire format- Parameters:
willetts
- number of willetts- Returns:
- OmniIndivisibleValue equal to number of willetts
-
checkValue
Make sure a BigInteger value is a valid value for OmniIndivisibleValue
- Parameters:
candidate
- value to check- Throws:
ArithmeticException
- if less than minimum or greater than maximum allowed value
-
checkValue
Make sure a BigInteger value is a valid value for OmniIndivisibleValue
Note: Since any positive long is valid, we just need to check that it's not less than MIN_VALUE
- Parameters:
candidate
- value to check.- Throws:
ArithmeticException
- if less than minimum allowed value
-
equals
-
toString
Convert toString
. Uses standard JVMtoString()
formats. ForOmniDivisibleValue
it is the same format asBigDecimal
(this means"0E-8"
forOmniDivisibleValue.ZERO
.) ForOmniIndivisibleValue
it is the same format asLong
. -
toPlainString
Convert toString
. ForOmniDivisibleValue
the same format asBigDecimal.toPlainString()
. ForOmniIndivisibleValue
it is the same astoString()
.- 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
-
getNumberType
- Specified by:
getNumberType
in classOmniValue
-
doubleValueExact
public double doubleValueExact()- Specified by:
doubleValueExact
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
.
-
round
- Specified by:
round
in classjavax.money.NumberValue
-
numberValue
Return value in preferred number type- Specified by:
numberValue
in classOmniValue
- Returns:
- value as represented in best/preferred number type
-
bigDecimalValue
Description copied from class:OmniValue
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
-
getPropertyType
- Specified by:
getPropertyType
in classOmniValue
- Returns:
- property type
-
plus
-
minus
-