package gw.currency uses gw.pl.currency.MonetaryAmount uses java.lang.IllegalArgumentException uses java.lang.Iterable @ReadOnly enhancement GWIterableOfMonetaryAmountCoreEnhancement: Iterable { /** * Return the average of the MonetaryAmount elements, * which must all be of the specified currency. */ function average(currency : Currency) : MonetaryAmount { return this.average(currency, \ amt -> amt) } /** * Sums up the MonetaryAmount elements, * which must all be of the specified currency. */ function sum(currency : Currency) : MonetaryAmount { return this.sum(currency, \ amt -> amt) } /** * Sums up the MonetaryAmount elements, which must all be of the same currency. * In addition the Iterable must have at least one non-null element to dynamically * determine the needed currency. * * MAKE SURE TO CALL THIS METHOD ONLY IF YOU KNOW THAT YOU HAVE AT LEAST ONE * NON-NULL MONETARYAMOUNT IN THE ITERABLE. */ function sumWithAtLeastOneNonNullCurrency() : MonetaryAmount { var currency = this.firstWhere(\ ma -> ma != null).Currency if (currency == null) { throw new IllegalArgumentException("This Iterable needs to have at least one non-null MonetaryAmount") } return this.sum(currency, \ amt -> amt) } }