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

public class OceanusMoney extends OceanusDecimal
Represents a Money object.
  • Field Details

    • BYTE_LEN

      public static final int BYTE_LEN
      Money Byte length.
      See Also:
    • ERROR_DIFFER

      static final String ERROR_DIFFER
      Invalid Currency error text.
      See Also:
    • DEFAULT_CURRENCY

      static final Currency DEFAULT_CURRENCY
      Default currency.
  • Constructor Details

    • OceanusMoney

      public OceanusMoney()
      Constructor for money of value zero in the default currency.
    • OceanusMoney

      public OceanusMoney(Currency pCurrency)
      Constructor for money of value zero.
      Parameters:
      pCurrency - the currency
    • OceanusMoney

      public OceanusMoney(OceanusMoney pMoney)
      Construct a new OceanusMoney by copying another money.
      Parameters:
      pMoney - the Money to copy
    • OceanusMoney

      public OceanusMoney(String pSource)
      Constructor for money from a decimal string.
      Parameters:
      pSource - The source decimal string
      Throws:
      IllegalArgumentException - on invalidly formatted argument
    • OceanusMoney

      public OceanusMoney(String pSource, Currency pCurrency)
      Constructor for money from a decimal string.
      Parameters:
      pSource - The source decimal string
      pCurrency - the currency
      Throws:
      IllegalArgumentException - on invalidly formatted argument
    • OceanusMoney

      protected OceanusMoney(OceanusUnits pUnits, OceanusPrice pPrice)
      Construct a new OceanusMoney by combining units and price.
      Parameters:
      pUnits - the number of units
      pPrice - the price of each unit
    • OceanusMoney

      public OceanusMoney(byte[] pBuffer)
      Create the decimal from a byte array.
      Parameters:
      pBuffer - the buffer
  • Method Details

    • getCurrency

      public Currency getCurrency()
      Access the currency.
      Returns:
      the currency
    • getWholeUnits

      public static OceanusMoney getWholeUnits(long pUnits, Currency pCurrency)
      Factory method for generating whole monetary units for a currency (e.g. £)
      Parameters:
      pUnits - the number of whole monetary units
      pCurrency - the currency
      Returns:
      the allocated money
    • getWholeUnits

      public static OceanusMoney getWholeUnits(long pUnits)
      Factory method for generating whole monetary units (e.g. £)
      Parameters:
      pUnits - the number of whole monetary units
      Returns:
      the allocated money
    • addAmount

      public void addAmount(OceanusMoney pValue)
      Add a monetary amount to the value.
      Parameters:
      pValue - The money to add to this one.
    • subtractAmount

      public void subtractAmount(OceanusMoney pValue)
      Subtract a monetary amount from the value.
      Parameters:
      pValue - The money to subtract from this one.
    • addValue

      public void addValue(OceanusDecimal pValue)
      Description copied from class: OceanusDecimal
      Add a Decimal to the value. The value of this Decimal is updated and the scale is maintained.
      Overrides:
      addValue in class OceanusDecimal
      Parameters:
      pValue - The Decimal to add to this one.
    • subtractValue

      public void subtractValue(OceanusDecimal pValue)
      Description copied from class: OceanusDecimal
      Subtract a Decimal from the value. The value of this Decimal is updated and the scale is maintained.
      Overrides:
      subtractValue in class OceanusDecimal
      Parameters:
      pValue - The decimal to subtract from this one.
    • changeCurrency

      public OceanusMoney changeCurrency(Currency pCurrency)
      Obtain value in different currency.
      Parameters:
      pCurrency - the currency to convert to
      Returns:
      the converted money in the new currency
    • convertCurrency

      public OceanusMoney convertCurrency(Currency pCurrency, OceanusRatio pRate)
      Obtain converted money.
      Parameters:
      pCurrency - the currency to convert to
      pRate - the conversion rate
      Returns:
      the converted money in the new currency
    • getDilutedMoney

      public OceanusMoney getDilutedMoney(OceanusRatio pDilution)
      obtain a Diluted money.
      Parameters:
      pDilution - the dilution factor
      Returns:
      the calculated value
    • valueAtRate

      public OceanusMoney valueAtRate(OceanusRate pRate)
      calculate the value of this money at a given rate.
      Parameters:
      pRate - the rate to calculate at
      Returns:
      the calculated value
    • valueAtRatio

      public OceanusMoney valueAtRatio(OceanusRatio pRatio)
      calculate the value of this money at a given ratio.
      Parameters:
      pRatio - the ratio to multiply by
      Returns:
      the calculated value
    • grossValueAtRate

      public OceanusMoney 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.
      Parameters:
      pRate - the rate to calculate at
      Returns:
      the calculated value
    • taxCreditAtRate

      public OceanusMoney 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 dividends
      Parameters:
      pRate - the rate to calculate at
      Returns:
      the calculated value
    • valueAtWeight

      public OceanusMoney valueAtWeight(OceanusMoney pWeight, OceanusMoney pTotal)
      calculate the value of this money at a given proportion (i.e. weight/total).
      Parameters:
      pWeight - the weight of this item
      pTotal - the total weight of all the items
      Returns:
      the calculated value
    • valueAtWeight

      public OceanusMoney valueAtWeight(OceanusUnits pWeight, OceanusUnits pTotal)
      calculate the value of this money at a given proportion (i.e. weight/total).
      Parameters:
      pWeight - the weight of this item
      pTotal - the total weight of all the items
      Returns:
      the calculated value
    • getDefaultCurrency

      public static Currency getDefaultCurrency()
      Obtain default currency.
      Returns:
      the default currency
    • equals

      public boolean equals(Object pThat)
      Overrides:
      equals in class OceanusDecimal
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class OceanusDecimal
    • toBytes

      public byte[] toBytes()
      Description copied from class: OceanusDecimal
      Convert the Decimal to a byte array.
      Overrides:
      toBytes in class OceanusDecimal
      Returns:
      the byte array