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 OmniIndivisibleValuestatic final BigIntegerstatic final longstatic final OmniIndivisibleValuestatic final BigIntegerstatic final longstatic final OmniIndivisibleValueFields inherited from class foundation.omni.OmniValue
MAX_WILLETTS, MIN_WILLETTS, willetts, willettsPerDivisible -
Method Summary
Modifier and TypeMethodDescriptionConvert to aBigDecimalvalue.static voidcheckValue(long candidate) Make sure a BigInteger value is a valid value for OmniIndivisibleValuestatic voidcheckValue(BigInteger candidate) Make sure a BigInteger value is a valid value for OmniIndivisibleValuedoubleReturn a double value.doublebooleanminus(OmniIndivisibleValue right) Return value in preferred number typestatic OmniIndivisibleValueof(long amount) Create OmniDivisibleValue of the specified amountstatic OmniIndivisibleValueof(BigInteger amount) static OmniIndivisibleValueofWilletts(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. ForOmniDivisibleValueit is the same format asBigDecimal(this means"0E-8"forOmniDivisibleValue.ZERO.) ForOmniIndivisibleValueit is the same format asLong. -
toPlainString
Convert toString. ForOmniDivisibleValuethe same format asBigDecimal.toPlainString(). ForOmniIndivisibleValueit is the same astoString().- Specified by:
toPlainStringin classOmniValue- Returns:
- Number as a string
-
toJsonFormattedString
Convert toString. The required format for OmniValues in JSON. ForOmniDivisibleValuethere is always at least one place after the decimal point (e.g."0.0"). This allows humans and parsers to easily tellOmniDivisibleValues fromOmniIndivisibleValues. Note: The'.'separator is always used regardless of the currentLocale.- Specified by:
toJsonFormattedStringin classOmniValue- Returns:
- Number as a string
-
toFormattedString
Convert toString. A human-readable format using locale-specific place-separators.- Specified by:
toFormattedStringin classOmniValue- Returns:
- Number as a string
-
getNumberType
- Specified by:
getNumberTypein classOmniValue
-
doubleValueExact
public double doubleValueExact()- Specified by:
doubleValueExactin 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:
doubleValuein classOmniValue- Returns:
- The value rounded to the nearest
double.
-
round
- Specified by:
roundin classjavax.money.NumberValue
-
numberValue
Return value in preferred number type- Specified by:
numberValuein classOmniValue- Returns:
- value as represented in best/preferred number type
-
bigDecimalValue
Description copied from class:OmniValueConvert to aBigDecimalvalue. This will be lossless. ForOmniIndivisibleValuetheBigDecimalvalue will be an integer, of course.- Specified by:
bigDecimalValuein classOmniValue- Returns:
- the value
-
getPropertyType
- Specified by:
getPropertyTypein classOmniValue- Returns:
- property type
-
plus
-
minus
-