View Javadoc

1   /*
2    * Copyright 2006 Christian Kalkhoff <me@ninan.info>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.plausj.bank.german.strategy.util;
18  
19  import net.sf.plausj.bank.german.CheckDigit;
20  
21  /**
22   * @author ninan
23   * 
24   */
25  public class Strategy52AlikeHelper {
26  
27  	public static int calculateSum(int[] legacyAccountNumber,
28  			int[] multiplicators) {
29  		int sum = 0;
30  		for (int i = 11; i >= 0; --i) {
31  			sum += legacyAccountNumber[i] * multiplicators[i];
32  		}
33  		int mod = sum % 11;
34  		return mod;
35  	}
36  
37  	public static CheckDigit getCheckSumFromMod(int mod, int weight, int pos) {
38  		CheckDigit cd = null;
39  		for (int i = 0; i < 10; ++i) {
40  			if ((mod + i * weight) % 11 == 10) {
41  				cd = new CheckDigit(pos, i);
42  			}
43  		}
44  		if (null == cd) {
45  			cd = new CheckDigit(CheckDigit.ALWAYS_INVALID, 0);
46  		}
47  
48  		return cd;
49  	}
50  
51  }