1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.plausj.bank.german.strategy;
18
19 import net.sf.plausj.bank.german.AccountCode;
20 import net.sf.plausj.bank.german.BankCode;
21 import net.sf.plausj.bank.german.CheckDigit;
22 import net.sf.plausj.bank.german.strategy.util.Strategy06AlikeHelper;
23
24 /**
25 * @author ninan
26 *
27 */
28 public class Strategy90 implements Strategy {
29
30 private static final int[] multiplicatorsMethodA = new int[] { 0, 0, 0, 7,
31 6, 5, 4, 3, 2 };
32
33 private static final int[] multiplicatorsMethodB = new int[] { 0, 0, 0, 0,
34 6, 5, 4, 3, 2 };
35
36 private static final int[] multiplicatorsMethodC = new int[] { 0, 0, 0, 0,
37 6, 5, 4, 3, 2 };
38
39 private static final int[] multiplicatorsMethodD = new int[] { 0, 0, 0, 0,
40 6, 5, 4, 3, 2 };
41
42 private static final int[] multiplicatorsMethodE = new int[] { 0, 0, 0, 0,
43 2, 1, 2, 1, 2 };
44
45 private static final int[] multiplicatorsMethodF = new int[] { 0, 0, 8, 7,
46 6, 5, 4, 3, 2 };
47
48 /**
49 * @see net.sf.plausj.bank.german.strategy.Strategy#calculateCheckDigit(net.sf.plausj.bank.german.BankCode,
50 * net.sf.plausj.bank.german.AccountCode)
51 */
52 public CheckDigit calculateCheckDigit(final BankCode bankCode,
53 final AccountCode accountCode) {
54
55 if (9 == accountCode.getDigitAtPos(2)) {
56
57 return calculateCheckDigitMethodF(accountCode);
58 } else {
59
60 CheckDigit cd = calculateCheckDigitMethodA(accountCode);
61 if (!accountCode.matchesCheckDigit(cd)) {
62 cd = calculateCheckDigitMethodB(accountCode);
63 if (!accountCode.matchesCheckDigit(cd)) {
64 cd = calculateCheckDigitMethodC(accountCode);
65 if (!accountCode.matchesCheckDigit(cd)) {
66 cd = calculateCheckDigitMethodD(accountCode);
67 if (!accountCode.matchesCheckDigit(cd)) {
68 cd = calculateCheckDigitMethodE(accountCode);
69 }
70 }
71 }
72 }
73 return cd;
74 }
75 }
76
77 private CheckDigit calculateCheckDigitMethodA(final AccountCode accountCode) {
78
79 int sum = Strategy06AlikeHelper.calculateSum(accountCode,
80 multiplicatorsMethodA);
81 int cd = Strategy06AlikeHelper.getCheckDigitFromSum(sum);
82 return new CheckDigit(9, cd);
83
84 }
85
86 private CheckDigit calculateCheckDigitMethodB(final AccountCode accountCode) {
87
88 int sum = Strategy06AlikeHelper.calculateSum(accountCode,
89 multiplicatorsMethodB);
90 int cd = Strategy06AlikeHelper.getCheckDigitFromSum(sum);
91 return new CheckDigit(9, cd);
92
93 }
94
95 private CheckDigit calculateCheckDigitMethodC(final AccountCode accountCode) {
96
97 int sum = Strategy06AlikeHelper.calculateSum(accountCode,
98 multiplicatorsMethodC);
99 int mod = sum % 7;
100 int cd = mod == 0 ? 0 : 7 - mod;
101 return new CheckDigit(9, cd);
102
103 }
104
105 private CheckDigit calculateCheckDigitMethodD(final AccountCode accountCode) {
106
107 int sum = Strategy06AlikeHelper.calculateSum(accountCode,
108 multiplicatorsMethodD);
109 int mod = sum % 9;
110 int cd = mod == 0 ? 0 : 9 - mod;
111 return new CheckDigit(9, cd);
112
113 }
114
115 private CheckDigit calculateCheckDigitMethodE(final AccountCode accountCode) {
116
117 int sum = Strategy06AlikeHelper.calculateSum(accountCode,
118 multiplicatorsMethodE);
119 int mod = sum % 10;
120 int cd = mod == 0 ? 0 : 10 - mod;
121 return new CheckDigit(9, cd);
122
123 }
124
125 private CheckDigit calculateCheckDigitMethodF(final AccountCode accountCode) {
126
127 int sum = Strategy06AlikeHelper.calculateSum(accountCode,
128 multiplicatorsMethodF);
129 int cd = Strategy06AlikeHelper.getCheckDigitFromSum(sum);
130 return new CheckDigit(9, cd);
131
132 }
133
134 }