KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > bank > Bank


1 /*
2   Renaud Pawlak, pawlak@cnam.fr, CEDRIC Laboratory, Paris, France.
3   Lionel Seinturier, Lionel.Seinturier@lip6.fr, LIP6, Paris, France.
4
5   JAC-Core is free software. You can redistribute it and/or modify it
6   under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation.
8   
9   JAC-Core is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13   This work uses the Javassist system - Copyright (c) 1999-2000
14   Shigeru Chiba, University of Tsukuba, Japan. All Rights Reserved. */

15
16 package org.objectweb.jac.samples.bank;
17
18 import org.objectweb.jac.lib.java.util.Hashtable;
19 import org.objectweb.jac.lib.java.util.Vector;
20 import org.objectweb.jac.samples.contacts.Person;
21
22 /**
23  * Defines the banks in the bank sample.<p>
24  *
25  * @see Account
26  * @see AccountManager
27  *
28  * @author <a HREF="mailto:maxime@aopsys.com">Maxime Pawlak</a>
29  * @author <a HREF="mailto:pawlak@cnam.fr">Renaud Pawlak</a>
30  */

31
32 public class Bank {
33
34    public long getBankNumber() { return bankNumber; }
35    public void setBankNumber( long bankNumber ) { this.bankNumber=bankNumber; }
36
37    /** The bank identifier. */
38    protected long bankNumber;
39
40    /** Stores the accounts within this bank. */
41    protected Hashtable accounts = new Hashtable();
42
43    protected Vector users = new Vector();
44
45    public void addUser(Person user) {
46       if( !users.contains(user) ) {
47          users.add(user);
48       }
49    }
50
51    /*public void setUsers(Person user) {
52       users.add(user);
53       }*/

54    
55    public Vector getUsers() {
56       return users;
57    }
58
59    /**
60     * Creates a new bank with a new number.
61     *
62     * @param bankNumber the bank number (should be unique) */

63
64    public Bank(long bankNumber) {
65       this.bankNumber = bankNumber;
66    }
67
68    /**
69     * Returns the accounts within this bank.<p>
70     *
71     * @return a hashtable that links numbers to the accounts
72     */

73
74    public Hashtable getAccounts() {
75       return accounts;
76    }
77
78    /**
79     * Adds an existing account to the accounts list.<p>
80     *
81     * @param account the new account
82     */

83
84    public void addAccount(Account account) {
85       accounts.put(new Long JavaDoc (account.accountNumber) , account) ;
86       account.setBank(this);
87       if( account.getOwner() != null ) {
88          users.add(account.getOwner());
89       }
90    }
91
92    /**
93     * Removes an existing account to the accounts list.<p>
94     *
95     * @param account the account to remove
96     */

97
98    public void removeAccount(Account account) {
99       accounts.remove(new Long JavaDoc(account.accountNumber));
100    }
101
102    /**
103     * Gets an account that belongs to this bank.<p>
104     *
105     * @param accountNumber the number of the account
106     * @return the corresponding account (null if not found)
107     */

108
109    public Account getAccount(long accountNumber) {
110       Account account;
111       account = (Account) accounts.get(new Long JavaDoc (accountNumber));
112       return account;
113    }
114
115    /**
116     * Returns a textual representation of the bank.<p>
117     *
118     * @return the text for the bank */

119
120    public String JavaDoc toString() {
121       return ""+bankNumber;
122    }
123
124
125 }
126
Popular Tags