Skip to content

Commit

Permalink
reduce use of instanceof
Browse files Browse the repository at this point in the history
use isCompositeAccount and isFinalAccount instead
  • Loading branch information
ar committed Oct 6, 2016
1 parent 1be33df commit 263c272
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions modules/minigl/src/main/java/org/jpos/gl/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public boolean isChart () {
public boolean isFinalAccount () {
return false;
}
public boolean isCompositeAccount () {
return !isFinalAccount();
}
/**
* Account's type
* @return "debit", "credit" or null.
Expand Down
16 changes: 8 additions & 8 deletions modules/minigl/src/main/java/org/jpos/gl/GLSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ else if (acct.isFinalAccount()) {
Criteria crit = session.createCriteria (GLEntry.class);

boolean hasChildren = false;
if (acct instanceof CompositeAccount) {
if (acct.isCompositeAccount()) {
Disjunction dis = Restrictions.disjunction();
for (Long l : getChildren (acct)) {
hasChildren = true;
Expand Down Expand Up @@ -1152,7 +1152,7 @@ else if (acct.isFinalAccount()) {
Criteria crit = session.createCriteria (GLEntry.class);

boolean hasChildren = false;
if (acct instanceof CompositeAccount) {
if (acct.isCompositeAccount()) {
Disjunction dis = Restrictions.disjunction();
for (Long l : getChildren (acct)) {
hasChildren = true;
Expand Down Expand Up @@ -1273,16 +1273,16 @@ else if (acct.isFinalAccount()) {
(Journal journal, Account acct, short[] layers, long maxId)
throws HibernateException, GLException
{
BigDecimal balance = null;
if (acct instanceof CompositeAccount) {
BigDecimal balance;
if (acct.isCompositeAccount()) {
balance = ZERO;
Iterator iter = ((CompositeAccount) acct).getChildren().iterator();
while (iter.hasNext()) {
Account a = (Account) iter.next();
balance = balance.add (createBalanceCache (journal, a, layers, maxId));
}
}
else if (acct instanceof FinalAccount) {
else if (acct.isFinalAccount()) {
lock (journal, acct);
balance = getBalances (journal, acct, null, true, layers, maxId) [0];
BalanceCache c = getBalanceCache (journal, acct, layers);
Expand Down Expand Up @@ -1482,14 +1482,14 @@ private AccountLock getLock (Journal journal, Account acct)
(Journal journal, Account acct, Date date, int threshold, short[] layers)
throws HibernateException, GLException
{
if (acct instanceof CompositeAccount) {
if (acct.isCompositeAccount()) {
Iterator iter = ((CompositeAccount) acct).getChildren().iterator();
while (iter.hasNext()) {
Account a = (Account) iter.next();
createCheckpoint0 (journal, a, date, threshold, layers);
}
}
else if (acct instanceof FinalAccount) {
else if (acct.isFinalAccount()) {
Date sod = Util.floor (date); // sod = start of day
invalidateCheckpoints (journal, new Account[] { acct }, sod, sod, layers);
BigDecimal b[] = getBalances (journal, acct, sod, false, layers, 0L);
Expand Down Expand Up @@ -1775,7 +1775,7 @@ public void overrideSafeWindow (long l) {
}
private void recurseChildren (Account acct, List<Long> list) {
for (Account a : acct.getChildren()) {
if (a instanceof FinalAccount)
if (a.isFinalAccount())
list.add (a.getId());
else recurseChildren (a, list);
}
Expand Down

0 comments on commit 263c272

Please sign in to comment.