UtilityAndArithmetic
Business Purpose
Provides static utility methods for common monetary operations such as comparison, aggregation, and safe arithmetic with null handling. [AI Inference] These complement the instance methods on monetary objects for convenience and safety.
Current Behaviors
MoneyUtils.isZero(MoneyProvider)checks if amount is zero MoneyUtils.java:53.MoneyUtils.isPositive(MoneyProvider)checks positivity MoneyUtils.java:65.MoneyUtils.max(Money, Money)returns the larger of two MoneyUtils.java:117.MoneyUtils.min(Money, Money)returns the smaller MoneyUtils.java:138.MoneyUtils.add(Money, Money)adds two amounts with currency check MoneyUtils.java:160.MoneyUtils.subtract(Money, Money)subtracts MoneyUtils.java:182.- Similar overloads for
BigMoneyMoneyUtils.java:204. Serhandles serialization viawriteExternalandreadExternal(Ser.java:72,112).
Technical Implementation
MoneyUtilsMoneyUtils.java:31 has no design pattern; it's a set of static methods.- Null parameters cause
NullPointerExceptionviacheckNotNullMoneyUtils.java:31. - Currency mismatches in
addandsubtractthrowCurrencyMismatchException(implied from methods). SerSer.java:72 implementsExternalizableand is marked IMMUTABLE_VALUE_OBJECT.Sermethods are@Override(Ser.java:72,112) and handle BigMoney and CurrencyUnit serialization.
Definition of Done
MoneyUtils.max(Money.of(USD, 10), Money.of(USD, 20))returns the Money with 20.MoneyUtils.add(Money.of(EUR, 5), Money.of(EUR, 3))returns a Money with EUR and amount 8.- Passing a null
MoneyProvidertoisZerothrowsNullPointerException. - Attempting
addwith different currencies throwsCurrencyMismatchException. - Serializing a
BigMoneyand deserializing results in an equal object. MoneyUtils.isNegative(BigMoney.of(GBP, -1))returns true.