+ String lastCurrency = null;
+ float lastCurrencyAmount = 0;
+ for (SimpleBalance b : getSimpleBalance()) {
+ task.throwIfCancelled();
+ final String currency = b.getCommodity();
+ final float amount = b.getAmount();
+ if (currency.equals(lastCurrency)) {
+ lastCurrencyAmount += amount;
+ }
+ else {
+ if (lastCurrency != null) {
+ acc.addAmount(lastCurrencyAmount, lastCurrency);
+ }
+ lastCurrency = currency;
+ lastCurrencyAmount = amount;
+ }
+ }
+ if (lastCurrency != null) {
+ acc.addAmount(lastCurrencyAmount, lastCurrency);
+ }
+ for (LedgerAccount p : createdParents)
+ acc.propagateAmountsTo(p);
+
+ return acc;
+ }
+
+ static public class SimpleBalance {
+ private String commodity;
+ private float amount;
+ public SimpleBalance(String commodity, float amount) {
+ this.commodity = commodity;
+ this.amount = amount;
+ }
+ public String getCommodity() {
+ return commodity;
+ }
+ public void setCommodity(String commodity) {
+ this.commodity = commodity;
+ }
+ public float getAmount() {
+ return amount;
+ }
+ public void setAmount(float amount) {
+ this.amount = amount;
+ }
+ }