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
23 /**
24 * @author ninan
25 *
26 */
27 public class Strategy77 implements Strategy {
28
29 private static final int[] multiplicatorsFirst = new int[] { 0, 0, 0, 0, 0,
30 5, 4, 3, 2, 1 };
31
32 private static final int[] multiplicatorsSecond = new int[] { 0, 0, 0, 0,
33 0, 5, 4, 3, 4, 5 };
34
35 /**
36 * @see net.sf.plausj.bank.german.strategy.Strategy#calculateCheckDigit(net.sf.plausj.bank.german.BankCode,
37 * net.sf.plausj.bank.german.AccountCode)
38 */
39 public CheckDigit calculateCheckDigit(final BankCode bankCode,
40 final AccountCode accountCode) {
41
42 int sum = calcSum(accountCode, multiplicatorsFirst);
43
44 int mod = sum % 11;
45
46 if (mod > 0) {
47
48 sum = calcSum(accountCode, multiplicatorsSecond);
49
50 mod = sum % 11;
51
52 if (mod > 0) {
53 return new CheckDigit(CheckDigit.ALWAYS_INVALID, 0);
54 }
55
56 }
57
58 return new CheckDigit(CheckDigit.ALWAYS_VALID, 0);
59
60 }
61
62 private int calcSum(AccountCode ac, int[] multiplicators) {
63 int sum = 0;
64 for (int i = AccountCode.ACCOUNT_CODE_MAX_LENGTH - 1; i >= 0; --i) {
65 sum += ac.getDigitAtPos(i) * multiplicators[i];
66 }
67
68 return sum;
69 }
70
71 }