+ public int getAnumpostings() {
+ return anumpostings;
+ }
+ public void setAnumpostings(int anumpostings) {
+ this.anumpostings = anumpostings;
+ }
+ public LedgerAccount toLedgerAccount(RetrieveTransactionsTask task,
+ HashMap<String, LedgerAccount> map) {
+ task.addNumberOfPostings(getAnumpostings());
+ final String accName = getAname();
+ LedgerAccount acc = map.get(accName);
+ if (acc != null)
+ throw new RuntimeException(
+ String.format("Account '%s' already present", acc.getName()));
+ String parentName = LedgerAccount.extractParentName(accName);
+ ArrayList<LedgerAccount> createdParents = new ArrayList<>();
+ LedgerAccount parent;
+ if (parentName == null) {
+ parent = null;
+ }
+ else {
+ parent = task.ensureAccountExists(parentName, map, createdParents);
+ parent.setHasSubAccounts(true);
+ }
+ acc = new LedgerAccount(accName, parent);
+ map.put(accName, acc);
+
+ 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);