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 MathContextstatic final intstatic OmniDivisibleValuestatic final longstatic final BigDecimalstatic OmniDivisibleValuestatic final longstatic final BigDecimalstatic OmniDivisibleValueFields inherited from class foundation.omni.OmniValue
MAX_WILLETTS, MIN_WILLETTS, willetts, willettsPerDivisible -
Method Summary
Modifier and TypeMethodDescriptionConvert to aBigDecimalvalue.bytestatic voidcheckValue(long candidate) Make sure a long value is a valid value for OmniDivisibleValuestatic voidcheckValue(BigDecimal candidate) Make sure a BigDecimal value is a valid value for OmniDivisibleValuedoubleReturn a double value.doublebooleanfloatlonglongintintgetScale()intintValue()intlonglongminus(OmniDivisibleValue right) Return value in preferred number typestatic OmniDivisibleValueof(long amount) Create OmniDivisibleValue of the specified amountstatic OmniDivisibleValueof(BigDecimal amount) Create OmniDivisibleValue of the specified amountstatic OmniDivisibleValueofWilletts(long willetts) Create OmniDivisibleValue from willetts/internal/wire formatplus(OmniDivisibleValue right) round(MathContext mathContext) shortConvert 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. ForOmniDivisibleValueit is the same format asBigDecimal(this means"0E-8"forZERO.) ForOmniIndivisibleValueit is the same format asLong. -
toPlainString
Convert toString. ForOmniDivisibleValuethe same format asBigDecimal.toPlainString(). ForOmniIndivisibleValueit is the same asOmniIndivisibleValue.toString().- 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
-
getPropertyType
- Specified by:
getPropertyTypein classOmniValue- Returns:
- property type
-
getNumberType
- Specified by:
getNumberTypein classOmniValue
-
numberValue
Return value in preferred number type- Specified by:
numberValuein classOmniValue- Returns:
- value as represented in best/preferred number type
-
getPrecision
public int getPrecision()- Overrides:
getPrecisionin classOmniValue
-
getScale
public int getScale() -
intValueExact
public int intValueExact()- Overrides:
intValueExactin classOmniValue
-
longValueExact
public long longValueExact()- Overrides:
longValueExactin classOmniValue
-
doubleValueExact
public double doubleValueExact()- Specified by:
doubleValueExactin classOmniValue
-
round
- Specified by:
roundin classjavax.money.NumberValue
-
getAmountFractionNumerator
public long getAmountFractionNumerator()- Overrides:
getAmountFractionNumeratorin classOmniValue
-
getAmountFractionDenominator
public long getAmountFractionDenominator()- Overrides:
getAmountFractionDenominatorin classOmniValue
-
byteValue
public byte byteValue() -
shortValue
public short shortValue()- Overrides:
shortValuein classOmniValue
-
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Overrides:
floatValuein 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.
-
bigDecimalValue
Convert to aBigDecimalvalue. This will be lossless. ForOmniIndivisibleValuetheBigDecimalvalue will be an integer, of course.- Specified by:
bigDecimalValuein classOmniValue- Returns:
- the value
-
plus
-
minus
-