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.Strategy52AlikeHelper;
23
24 /**
25 * @author ninan
26 *
27 */
28 public class Strategy53 implements Strategy {
29
30 private static final int[] multiplicators = new int[] { 4, 2, 1, 6, 3, 7,
31 9, 10, 5, 8, 4, 2 };
32
33 /**
34 * @see net.sf.plausj.bank.german.strategy.Strategy#calculateCheckDigit(net.sf.plausj.bank.german.BankCode,
35 * net.sf.plausj.bank.german.AccountCode)
36 */
37 public CheckDigit calculateCheckDigit(final BankCode bankCode,
38 final AccountCode accountCode) {
39
40 if (9 == accountCode.getDigitAtPos(0)) {
41 return new Strategy20().calculateCheckDigit(bankCode, accountCode);
42 }
43
44 int offset = calculateOffset(bankCode, accountCode);
45 int cdWeight = multiplicators[5 + offset];
46 int[] legacyAccountNumber = buildEserLegacyAccountCode(bankCode,
47 accountCode, offset);
48
49 int mod = Strategy52AlikeHelper.calculateSum(legacyAccountNumber,
50 multiplicators);
51
52 return Strategy52AlikeHelper.getCheckSumFromMod(mod, cdWeight, 2);
53
54 }
55
56 private int calculateOffset(final BankCode bankCode,
57 final AccountCode accountCode) {
58
59 int offset = 0;
60 for (int i = 0; i < 6; ++i) {
61 if (0 != accountCode.getDigitAtPos(i + 5)) {
62 offset = i;
63 break;
64 }
65 }
66 return offset;
67 }
68
69 private int[] buildEserLegacyAccountCode(final BankCode bankCode,
70 final AccountCode accountCode, final int offset) {
71
72 int[] elac = new int[12];
73
74 elac[0 + offset] = bankCode.getDigitAtPos(4);
75 elac[1 + offset] = bankCode.getDigitAtPos(5);
76 elac[2 + offset] = accountCode.getDigitAtPos(2);
77 elac[3 + offset] = bankCode.getDigitAtPos(7);
78 elac[4 + offset] = accountCode.getDigitAtPos(1);
79
80 for (int i = offset; i < 6; ++i) {
81 elac[i + 6] = accountCode.getDigitAtPos(4 + i);
82 }
83
84 return elac;
85
86 }
87 }