Class Money

java.lang.Object
ch.tocco.nice2.toolbox.api.util.Money
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Money>

public class Money extends Object implements Serializable, Comparable<Money>, Cloneable
This value class handles money.

The code is based on the proposal of Martin Fowler and Matt Foemmel as read in "Patterns of Enterprise Application Architecture" (p.488ff) where a Money class was discussed and introduced.
See Also:
  • Constructor Details

    • Money

      public Money(double amount, Currency currency)
    • Money

      public Money(long amount, Currency currency)
    • Money

      public Money(BigDecimal amount, Currency cur)
    • Money

      public Money(String amountAndCurrency)
    • Money

      public Money(BigDecimal amount, Currency currency, RoundingMode roundingMode)
      Creates a new money of the provided m_amount and m_currency.

      User defined rounding mode is used - this method is alluded to in Fowlers book if not actually defined there.

    • Money

      public Money(Money src)
      Cloning ctor.
    • Money

      protected Money()
      used to skip calculations in public constructors
  • Method Details

    • getFormatter

      public static NumberFormat getFormatter(Currency currency, @Nullable @Nullable Locale locale)
    • getAmountFormatter

      public static NumberFormat getAmountFormatter(@Nullable @Nullable Locale locale)
    • getCurrency

      public Currency getCurrency()
    • getAmount

      public BigDecimal getAmount()
    • withCurrency

      public Money withCurrency(Currency currency)
    • withAmount

      public Money withAmount(long amount)
    • withAmount

      public Money withAmount(double amount)
    • withAmount

      public Money withAmount(BigDecimal amount)
    • doubleValue

      public double doubleValue()
      Return the amount as double value.
    • add

      public Money add(Money other)
    • subtract

      public Money subtract(Money other)
    • multiply

      public Money multiply(double fac)
    • multiply

      public Money multiply(BigDecimal fac)
    • multiply

      public Money multiply(BigDecimal fac, RoundingMode roundingmode)
    • divideBy

      public Money divideBy(int div)
    • divideBy

      public Money divideBy(double div)
    • divideBy

      public Money divideBy(BigDecimal div)
    • divideBy

      public Money divideBy(BigDecimal div, RoundingMode roundingMode)
    • allocate

      public Money[] allocate(long[] ratios)
    • allocate

      public Money[] allocate(int n)
    • euros

      public static Money euros(double amount)
    • dollars

      public static Money dollars(double amount)
    • franc

      public static Money franc(double amount)
    • convertCurrency

      public Money convertCurrency(double factor, Currency currency)
    • convertCurrency

      public Money convertCurrency(BigDecimal factor, Currency currency)
    • parse

      @Nullable public static @Nullable Money parse(@Nullable @Nullable String amountAndCurrency)
    • compareTo

      public int compareTo(Money other)
      Specified by:
      compareTo in interface Comparable<Money>
    • isGreaterThan

      public boolean isGreaterThan(Money other)
    • isLowerThan

      public boolean isLowerThan(Money other)
    • toParsableString

      public String toParsableString()
    • toString

      public String toString(@Nullable @Nullable Locale locale)
    • formatAmount

      public String formatAmount(@Nullable @Nullable Locale locale)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • clone

      public Money clone()
      Overrides:
      clone in class Object