View Javadoc
1   package generated.model.de.fhdw.partner;
2   
3   import de.fhdw.wtf.context.model.AnyType;
4   import de.fhdw.wtf.context.model.collections.MutableMap;
5   import de.fhdw.wtf.persistence.meta.UserObject;
6   
7   /**
8    * Account locator.
9    */
10  public class IBAN_Finder extends AnyType {
11  	
12  	/**
13  	 * Maps triples (country, bank identifier, account number) to bank accounts.
14  	 */
15  	private MutableMap<Country, MutableMap<Bankidentifier, MutableMap<AccountNumber, Account>>> accountTree;
16  	
17  	/**
18  	 * Creates an empty IBAN_Finder.
19  	 */
20  	public IBAN_Finder() {
21  		this.accountTree = new MutableMap<>();
22  	}
23  	
24  	/**
25  	 * Loads object from database.
26  	 * 
27  	 * @param userObject
28  	 *            The underlying user object.
29  	 */
30  	public IBAN_Finder(final UserObject userObject) {
31  		super(userObject);
32  	}
33  	
34  	/**
35  	 * Maps a triple (country, bank identifier, account number) to an account.
36  	 * 
37  	 * @param country
38  	 *            The country.
39  	 * @param blz
40  	 *            The bank identifier.
41  	 * @param number
42  	 *            The account number.
43  	 * @return The account or null if no such account exists.
44  	 */
45  	public Account findAccount(final Country country, final Bankidentifier blz, final AccountNumber number) {
46  		final MutableMap<Bankidentifier, MutableMap<AccountNumber, Account>> countryMap = this.accountTree.get(country);
47  		if (countryMap != null) {
48  			final MutableMap<AccountNumber, Account> bankMap = countryMap.get(blz);
49  			if (bankMap != null) {
50  				final Account acc = bankMap.get(number);
51  				return acc;
52  			}
53  		}
54  		return null;
55  	}
56  	
57  	/**
58  	 * Adds a account to the locator map.
59  	 * 
60  	 * @param country
61  	 *            The country.
62  	 * @param blz
63  	 *            The bank identifier.
64  	 * @param number
65  	 *            The account number.
66  	 * @param account
67  	 *            The account.
68  	 */
69  	public void addAccount(final Country country,
70  			final Bankidentifier blz,
71  			final AccountNumber number,
72  			final Account account) {
73  		MutableMap<Bankidentifier, MutableMap<AccountNumber, Account>> countryMap = this.accountTree.get(country);
74  		if (countryMap != null) {
75  			MutableMap<AccountNumber, Account> bankMap = countryMap.get(blz);
76  			if (bankMap != null) {
77  				bankMap.put(number, account);
78  			} else {
79  				bankMap = new MutableMap<>();
80  				bankMap.put(number, account);
81  				countryMap.put(blz, bankMap);
82  			}
83  		} else {
84  			countryMap = new MutableMap<>();
85  			final MutableMap<AccountNumber, Account> bankMap = new MutableMap<>();
86  			bankMap.put(number, account);
87  			countryMap.put(blz, bankMap);
88  			this.accountTree.put(country, countryMap);
89  		}
90  	}
91  }