Money implements Serializable, Comparable<Object> { public Money[] allocate(int targets) { Money[] results = new Money[targets]; Money lowResult = newMoneyWithSameCurrency(this.cent / targets); Money highResult = newMoneyWithSameCurrency(lowResult.cent + 1); int remainder = (int) this.cent % targets; for (int i = 0; i < remainder; i++) { results[i] = highResult; } for (int i = remainder; i < targets; i++) { results[i] = lowResult; } return results; } Money();  Money(long yuan, int cent);  Money(long yuan, int cent, Currency currency);  Money(String amount);  Money(String amount, Currency currency);  Money(String amount, Currency currency, int roundingMode);  Money(double amount);  Money(double amount, Currency currency);  Money(BigDecimal amount);  Money(BigDecimal amount, int roundingMode);  Money(BigDecimal amount, Currency currency);  Money(BigDecimal amount, Currency currency, int roundingMode); BigDecimal getAmount(); void setAmount(BigDecimal amount); long getCent(); String getCurrencyCode(); int getCentFactor(); boolean equals(Object other); boolean equals(Money other); int hashCode(); int compareTo(Object other); int compareTo(Money other); boolean greaterThan(Money other); Money add(Money other); Money addTo(Money other); Money subtract(Money other); Money subtractFrom(Money other); Money multiply(long val); Money multiplyBy(long val); Money multiply(double val); Money multiplyBy(double val); Money multiply(BigDecimal val); Money multiplyBy(BigDecimal val); Money multiply(BigDecimal val, int roundingMode); Money multiplyBy(BigDecimal val, int roundingMode); Money divide(double val); Money divideBy(double val); Money divide(BigDecimal val); Money divide(BigDecimal val, int roundingMode); Money divideBy(BigDecimal val); Money divideBy(BigDecimal val, int roundingMode); Money[] allocate(int targets); Money[] allocate(long[] ratios); String toString(); String dump(); void setCent(long cent); String getDisplayUnit(); String getDisplayUnit(Locale e); static final String DEFAULT_CURRENCY_CODE; static final int DEFAULT_ROUNDING_MODE; }
@Test public void allocate() { for (Money mon : money.allocate(10)) { assertEquals(101, mon.getCent()); } Money xMoney = new Money(); for (Money mon : money.allocate(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })) { xMoney.addTo(mon); } assertEquals(money, xMoney); }