Class OceanusMoney
java.lang.Object
io.github.tonywasher.joceanus.oceanus.decimal.OceanusDecimal
io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney
- All Implemented Interfaces:
Comparable<OceanusDecimal>
- Direct Known Subclasses:
OceanusPrice
Represents a Money object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMoney Byte length.(package private) static final CurrencyDefault currency.(package private) static final StringInvalid Currency error text.Fields inherited from class io.github.tonywasher.joceanus.oceanus.decimal.OceanusDecimal
MAX_DECIMALS, RADIX_TEN -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor for money of value zero in the default currency.OceanusMoney(byte[] pBuffer) Create the decimal from a byte array.OceanusMoney(OceanusMoney pMoney) Construct a new OceanusMoney by copying another money.protectedOceanusMoney(OceanusUnits pUnits, OceanusPrice pPrice) Construct a new OceanusMoney by combining units and price.OceanusMoney(String pSource) Constructor for money from a decimal string.OceanusMoney(String pSource, Currency pCurrency) Constructor for money from a decimal string.OceanusMoney(Currency pCurrency) Constructor for money of value zero. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAmount(OceanusMoney pValue) Add a monetary amount to the value.voidaddValue(OceanusDecimal pValue) Add a Decimal to the value.changeCurrency(Currency pCurrency) Obtain value in different currency.convertCurrency(Currency pCurrency, OceanusRatio pRate) Obtain converted money.booleanAccess the currency.static CurrencyObtain default currency.getDilutedMoney(OceanusRatio pDilution) obtain a Diluted money.static OceanusMoneygetWholeUnits(long pUnits) Factory method for generating whole monetary units (e.g. £)static OceanusMoneygetWholeUnits(long pUnits, Currency pCurrency) Factory method for generating whole monetary units for a currency (e.g. £)grossValueAtRate(OceanusRate pRate) calculate the gross value of this money at a given rate used to convert from net to gross values form interest and dividends.inthashCode()voidsubtractAmount(OceanusMoney pValue) Subtract a monetary amount from the value.voidsubtractValue(OceanusDecimal pValue) Subtract a Decimal from the value.taxCreditAtRate(OceanusRate pRate) calculate the TaxCredit value of this money at a given rate used to convert from net to gross. values form interest and dividendsbyte[]toBytes()Convert the Decimal to a byte array.valueAtRate(OceanusRate pRate) calculate the value of this money at a given rate.valueAtRatio(OceanusRatio pRatio) calculate the value of this money at a given ratio.valueAtWeight(OceanusMoney pWeight, OceanusMoney pTotal) calculate the value of this money at a given proportion (i.e. weight/total).valueAtWeight(OceanusUnits pWeight, OceanusUnits pTotal) calculate the value of this money at a given proportion (i.e. weight/total).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, floatValue, getFactor, 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, toString, unscaledValue
-
Field Details
-
BYTE_LEN
public static final int BYTE_LENMoney Byte length.- See Also:
-
ERROR_DIFFER
Invalid Currency error text.- See Also:
-
DEFAULT_CURRENCY
Default currency.
-
-
Constructor Details
-
OceanusMoney
public OceanusMoney()Constructor for money of value zero in the default currency. -
OceanusMoney
Constructor for money of value zero.- Parameters:
pCurrency- the currency
-
OceanusMoney
Construct a new OceanusMoney by copying another money.- Parameters:
pMoney- the Money to copy
-
OceanusMoney
Constructor for money from a decimal string.- Parameters:
pSource- The source decimal string- Throws:
IllegalArgumentException- on invalidly formatted argument
-
OceanusMoney
Constructor for money from a decimal string.- Parameters:
pSource- The source decimal stringpCurrency- the currency- Throws:
IllegalArgumentException- on invalidly formatted argument
-
OceanusMoney
Construct a new OceanusMoney by combining units and price.- Parameters:
pUnits- the number of unitspPrice- the price of each unit
-
OceanusMoney
public OceanusMoney(byte[] pBuffer) Create the decimal from a byte array.- Parameters:
pBuffer- the buffer
-
-
Method Details
-
getCurrency
Access the currency.- Returns:
- the currency
-
getWholeUnits
Factory method for generating whole monetary units for a currency (e.g. £)- Parameters:
pUnits- the number of whole monetary unitspCurrency- the currency- Returns:
- the allocated money
-
getWholeUnits
Factory method for generating whole monetary units (e.g. £)- Parameters:
pUnits- the number of whole monetary units- Returns:
- the allocated money
-
addAmount
Add a monetary amount to the value.- Parameters:
pValue- The money to add to this one.
-
subtractAmount
Subtract a monetary amount from the value.- Parameters:
pValue- The money to subtract from this one.
-
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.
-
changeCurrency
Obtain value in different currency.- Parameters:
pCurrency- the currency to convert to- Returns:
- the converted money in the new currency
-
convertCurrency
Obtain converted money.- Parameters:
pCurrency- the currency to convert topRate- the conversion rate- Returns:
- the converted money in the new currency
-
getDilutedMoney
obtain a Diluted money.- Parameters:
pDilution- the dilution factor- Returns:
- the calculated value
-
valueAtRate
calculate the value of this money at a given rate.- Parameters:
pRate- the rate to calculate at- Returns:
- the calculated value
-
valueAtRatio
calculate the value of this money at a given ratio.- Parameters:
pRatio- the ratio to multiply by- Returns:
- the calculated value
-
grossValueAtRate
calculate the gross value of this money at a given rate used to convert from net to gross values form interest and dividends.- Parameters:
pRate- the rate to calculate at- Returns:
- the calculated value
-
taxCreditAtRate
calculate the TaxCredit value of this money at a given rate used to convert from net to gross. values form interest and dividends- Parameters:
pRate- the rate to calculate at- Returns:
- the calculated value
-
valueAtWeight
calculate the value of this money at a given proportion (i.e. weight/total).- Parameters:
pWeight- the weight of this itempTotal- the total weight of all the items- Returns:
- the calculated value
-
valueAtWeight
calculate the value of this money at a given proportion (i.e. weight/total).- Parameters:
pWeight- the weight of this itempTotal- the total weight of all the items- Returns:
- the calculated value
-
getDefaultCurrency
Obtain default currency.- Returns:
- the default currency
-
equals
- Overrides:
equalsin classOceanusDecimal
-
hashCode
public int hashCode()- Overrides:
hashCodein classOceanusDecimal
-
toBytes
public byte[] toBytes()Description copied from class:OceanusDecimalConvert the Decimal to a byte array.- Overrides:
toBytesin classOceanusDecimal- Returns:
- the byte array
-