01: package bank;
02:
03: import java.util.Collection;
04: import java.util.Iterator;
05: import java.util.ArrayList;
06:
07: /**
08: * @author S.Chassande-Barrioz
09: */
10: public class Bank {
11: protected String name;
12: protected Collection agencies;
13:
14: public Bank() {
15: }
16:
17: public Bank(String name) {
18: this .name = name;
19: agencies = new ArrayList();
20: }
21:
22: public Agency getAgency(String name) {
23: Iterator it = agencies.iterator();
24: while (it.hasNext()) {
25: Agency a = (Agency) it.next();
26: if (a.name.equals(name)) {
27: return a;
28: }
29: }
30: return null;
31: }
32:
33: public synchronized Agency createAgency(String name) {
34: Agency a = getAgency(name);
35: if (a == null) {
36: a = new Agency(name, this);
37: agencies.add(a);
38: }
39: return a;
40: }
41: }
|