This is an automated email from the git hooks/post-receive script. New change to branch feature/1289-SearchEntriescomputeSold in repository lima. See http://git.chorem.org/lima.git from 9e607a7 refs #1289 calcul de la colonne Solde dans l'onglet recherche des entrées new 2a3623d refs #1289refactoring The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 2a3623d50ee78b0d4ee6c3a4bd485dfdfb06c32d Author: dcosse <cosse@codelutin.com> Date: Wed Sep 9 18:51:12 2015 +0200 refs #1289refactoring Summary of changes: .../ui/financialtransaction/BalanceColumn.java | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1289-SearchEntriescomputeSold in repository lima. See http://git.chorem.org/lima.git commit 2a3623d50ee78b0d4ee6c3a4bd485dfdfb06c32d Author: dcosse <cosse@codelutin.com> Date: Wed Sep 9 18:51:12 2015 +0200 refs #1289refactoring --- .../ui/financialtransaction/BalanceColumn.java | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/BalanceColumn.java b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/BalanceColumn.java index 70dba87..9c95ea6 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/BalanceColumn.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/BalanceColumn.java @@ -42,28 +42,35 @@ public class BalanceColumn extends AbstractColumn<FinancialTransactionTableModel @Override public Object getValueAt(int row) { - BigDecimal result = BigDecimal.ZERO; - FinancialTransaction transaction = tableModel.getTransactionAt(row); - if (row == 0) { - Entry entry = tableModel.get(row); - result = entry.isDebit() ? result.subtract(entry.getAmount()) : result.add(entry.getAmount()); - } else { - int i = 1; - Entry previousEntry = tableModel.get(row - 1); - FinancialTransaction previousTransaction = previousEntry.getFinancialTransaction(); + BigDecimal balance = BigDecimal.ZERO; + balance = getRowBalance(row, balance); - Entry currentEntry = tableModel.get(row); - result = currentEntry.isDebit() ? result.subtract(currentEntry.getAmount()) : result.add(currentEntry.getAmount()); + if (row > 0) { + balance = addPreviousTransactionEntryBalance(row, balance); + } + return balance; + } + + protected BigDecimal getRowBalance(int row, BigDecimal result) { + Entry currentEntry = tableModel.get(row); + result = currentEntry.isDebit() ? result.subtract(currentEntry.getAmount()) : result.add(currentEntry.getAmount()); + return result; + } - if (transaction == previousTransaction) { - while (row - i >= 0 && tableModel.get(row - i).getFinancialTransaction() == transaction) { - Entry prevEntry = tableModel.get(row - i); - result = prevEntry.isDebit() ? result.subtract(prevEntry.getAmount()) : result.add(prevEntry.getAmount()); - i++; - } - } + protected BigDecimal addPreviousTransactionEntryBalance(int row, BigDecimal result) { + FinancialTransaction rowTransaction = tableModel.getTransactionAt(row); + int i = 1; + while (isSameTransaction(row, rowTransaction, i)) { + result = getRowBalance(row - i, result); + i++; } + return result; } + + protected boolean isSameTransaction(int row, FinancialTransaction transaction, int i) { + return row - i >= 0 && tableModel.get(row - i).getFinancialTransaction() == transaction; + } + } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm