Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 15 | arune | 1 | /* |
| 2 | * MbInternetAddressList.java |
||
| 3 | * |
||
| 4 | * Created on den 26 augusti 2003, 11:36 |
||
| 5 | */ |
||
| 6 | package Macbeth.System; |
||
| 7 | |||
| 8 | import java.util.*; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Maintains a list of internet addresses, where |
||
| 12 | * each address is mapped to a name. |
||
| 13 | * @author Jimmy |
||
| 14 | */ |
||
| 15 | public class MbInternetAddressList { |
||
| 16 | private HashMap addresses; |
||
| 17 | |||
| 18 | /** Creates a new instance of MbInternetAddressList */ |
||
| 19 | public MbInternetAddressList() { |
||
| 20 | addresses = new HashMap(32); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Adds an address to the list and maps it to the given name. |
||
| 25 | * @param name The name to which the address will be mapped. |
||
| 26 | * @param address The actual address. |
||
| 27 | */ |
||
| 28 | public void addAddress(String name, MbInternetAddress address) { |
||
| 29 | addresses.put(name, address); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Gets an address from the list. |
||
| 34 | * @param name The name of the address you want to get. |
||
| 35 | * @return The address that is mapped to this name. Null if no such name is found in list. |
||
| 36 | */ |
||
| 37 | public MbInternetAddress getAddress(String name) { |
||
| 38 | MbInternetAddress address = (MbInternetAddress)addresses.get(name); |
||
| 39 | return address; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Removes an address from the list. |
||
| 44 | * @param name The name of the address you want to remove. |
||
| 45 | */ |
||
| 46 | public void removeAddress(String name) { |
||
| 47 | addresses.remove(name); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Gets an array that contains the names of all addresses. |
||
| 52 | * @return An array with all names. |
||
| 53 | */ |
||
| 54 | public String[] getNameList() { |
||
| 55 | String[] list = new String[addresses.size()]; |
||
| 56 | int i=0; |
||
| 57 | Iterator it = addresses.keySet().iterator(); |
||
| 58 | while (it.hasNext()) { |
||
| 59 | String name = (String)it.next(); |
||
| 60 | list[i++] = name; |
||
| 61 | } |
||
| 62 | return list; |
||
| 63 | } |
||
| 64 | } |