Skip to content

Commit 1a920e8

Browse files
Changed access, added getters and setters with verification logic
1 parent 35c992c commit 1a920e8

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

src/main/java/com/diffblue/corebanking/compliance/CheckCompliance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void checkAccountCompliance(List<Account> accountsToVerify) {
2727

2828
// Loop through all the existing compliance rules
2929
for (ComplianceRule rule : COMPLIANCE_RULES) {
30-
rule.ValidateAccountCompliance(a);
30+
rule.validateAccountCompliance(a);
3131
}
3232
}
3333
}

src/main/java/com/diffblue/corebanking/compliance/rules/ComplianceRule.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,66 @@
66

77
public abstract class ComplianceRule {
88

9-
protected final List<Account> currentFailedAccounts = new ArrayList<Account>();
10-
protected final List<Account> currentPassedAccounts = new ArrayList<Account>();
9+
private final List<Account> currentFailedAccounts = new ArrayList<Account>();
10+
private final List<Account> currentPassedAccounts = new ArrayList<Account>();
11+
12+
/**
13+
*
14+
* @param account
15+
*/
16+
public void setCurrentFailedAccount(Account account) {
17+
if (currentFailedAccounts.contains(account)) {
18+
throw new IllegalStateException();
19+
}
20+
currentFailedAccounts.add(account);
21+
}
22+
23+
/**
24+
*
25+
* @param account
26+
*/
27+
public void setCurrentPassedAccount(Account account) {
28+
if (currentPassedAccounts.contains(account)) {
29+
throw new IllegalStateException();
30+
}
31+
currentPassedAccounts.add(account);
32+
}
33+
34+
/**
35+
*
36+
* @return
37+
*/
38+
public List<Account> getCurrentFailedAccounts() {
39+
return this.currentFailedAccounts;
40+
}
41+
42+
/**
43+
*
44+
* @return
45+
*/
46+
public List<Account> getCurrentPassedAccounts() {
47+
return this.currentPassedAccounts;
48+
}
1149

1250
/**
1351
* Checks if the passed account passes or fails this rule.
1452
*
1553
* @param account The account to verify compliance.
1654
*/
17-
public abstract boolean ValidateAccountCompliance(Account account);
55+
public abstract void validateAccountCompliance(Account account);
1856

1957
/** Purges all accounts from the rules. */
2058
public void purgeAccounts() {
2159
this.currentFailedAccounts.clear();
2260
this.currentPassedAccounts.clear();
2361
}
62+
63+
/**
64+
*
65+
* @param account
66+
*/
67+
public void forgetAccount(Account account) {
68+
this.currentFailedAccounts.remove(account);
69+
this.currentPassedAccounts.remove(account);
70+
}
2471
}

src/main/java/com/diffblue/corebanking/compliance/rules/ComplianceRuleBalanceAboveOrEqualToZero.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@ public class ComplianceRuleBalanceAboveOrEqualToZero extends ComplianceRule {
99
*
1010
* @param account The account to verify compliance.
1111
*/
12-
public boolean ValidateAccountCompliance(Account account) {
12+
public void validateAccountCompliance(Account account) {
1313

1414
// Make sure the account does not belong to any list.
15-
currentFailedAccounts.remove(account);
16-
currentPassedAccounts.remove(account);
15+
this.forgetAccount(account);
1716

1817
// Check if this account passes or fails this rule.
1918
if (account.getCurrentBalance() >= 0) {
20-
currentPassedAccounts.add(account);
21-
return true;
19+
setCurrentPassedAccount(account);
2220
} else {
23-
currentFailedAccounts.add(account);
24-
return false;
21+
setCurrentFailedAccount(account);
2522
}
2623
}
2724
}

0 commit comments

Comments
 (0)