Skip to content

MoneyRepresentation

Business Purpose

Provides the core monetary value objects Money and BigMoney that represent an amount in a given currency, with full support for arithmetic, scaling, and currency safety. [AI Inference] These classes serve as the primary data types for any financial calculation in the library.

Current Behaviors

  • BigMoney.of(currency, BigDecimal) creates a BigMoney with default scale BigMoney.java:78.
  • BigMoney.ofScale(currency, amount, scale) creates with an explicit scale BigMoney.java:136.
  • BigMoney.plus(BigMoneyProvider) performs addition with currency validation BigMoney.java:856.
  • BigMoney.minus(BigMoneyProvider) performs subtraction BigMoney.java:1068.
  • BigMoney.multipliedBy(BigDecimal) multiplies amount BigMoney.java:1253.
  • Money.of(currency, BigDecimal) creates a Money with currency-determined scale Money.java:70.
  • Money.plus(BigDecimal, RoundingMode) adds with explicit rounding Money.java:776.
  • Money.divideBy(BigDecimal, RoundingMode) divides with rounding Money.java:1073.
  • Both classes implement BigMoneyProvider (BigMoney.java:1561, Money.java:1195).
  • BigMoney.getCurrencyUnit() returns the currency BigMoney.java:456.
  • Money.getScale() returns the scale of the amount Money.java:457.
  • BigMoney.isSameCurrency(BigMoney) checks currency equality BigMoney.java:1595.
  • BigMoney.compareTo(BigMoney) provides ordering BigMoney.java:1608.
  • Money.equals(Object) and hashCode() are overridden (Money.java:1314, 1330).

Technical Implementation

  • BigMoney BigMoney.java:78 and Money Money.java:70 are designed as IMMUTABLE_VALUE_OBJECT (design pattern detected).
  • All arithmetic methods are decorated with @Override where they override superclass methods (e.g., BigMoney.java:1561, Money.java:1195).
  • Static factory methods of use @FromString annotation for parsing (BigMoney.java:374, Money.java:337).
  • Currency mismatch is enforced via CurrencyMismatchException BigMoney.java:808.
  • Scale control is explicit with methods like withScale, retainScale (BigMoney.java:526, 972).

Definition of Done

  • A call to BigMoney.of(CurrencyUnit.GBP, BigDecimal.TEN) returns a BigMoney instance with GBP currency and amount 10.
  • Adding two BigMoney objects with different currencies throws CurrencyMismatchException.
  • Calling Money.of(CurrencyUnit.JPY, new BigDecimal("12.345")) rounds the amount to JPY scale (zero decimals) using default rounding.
  • BigMoney.plus(BigMoneyProvider) accepts both BigMoney and Money implementations.
  • Money.toBigMoney() returns a BigMoney with the same amount and currency.
  • The compareTo method correctly orders by amount when currencies are equal, and throws exception when currencies differ.