noteFocusChanged(fi.position - 1, fi.element);
setItems(newList);
}
- void noteFocusChanged(int position, FocusedElement element) {
+ void noteFocusChanged(int position, @Nullable FocusedElement element) {
FocusInfo present = focusInfo.getValue();
if (present == null || present.position != position || present.element != element)
focusInfo.setValue(new FocusInfo(position, element));
LedgerTransaction tr = head.asLedgerTransaction();
tr.setComment(head.getComment());
- LedgerTransactionAccount emptyAmountAccount = null;
+ List<LedgerTransactionAccount> emptyAmountAccounts = new ArrayList<>();
float emptyAmountAccountBalance = 0;
for (int i = 1; i < list.size(); i++) {
TransactionAccount item = list.get(i)
emptyAmountAccountBalance += item.getAmount();
}
else {
- emptyAmountAccount = acc;
+ emptyAmountAccounts.add(acc);
}
tr.addAccount(acc);
}
- if (emptyAmountAccount != null)
- emptyAmountAccount.setAmount(-emptyAmountAccountBalance);
+ if (emptyAmountAccounts.size() > 0) {
+ if (emptyAmountAccounts.size() > 1 && !Misc.isZero(emptyAmountAccountBalance))
+ throw new RuntimeException(String.format(Locale.US,
+ "Should not happen. %d accounts with non zero amount to distribute (%5" +
+ ".3f)"));
+ for (LedgerTransactionAccount a : emptyAmountAccounts)
+ a.setAmount(-emptyAmountAccountBalance);
+ }
return tr;
}
public static class FocusInfo {
int position;
FocusedElement element;
- public FocusInfo(int position, FocusedElement element) {
+ public FocusInfo(int position, @Nullable FocusedElement element) {
this.position = position;
this.element = element;
}