KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Person


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
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 import java.util.ArrayList JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * See Main.java.
24  */

25 public class Person {
26   private int id;
27   private String JavaDoc category;
28   private String JavaDoc name;
29   private HashMap JavaDoc emails = new HashMap JavaDoc();
30   private List JavaDoc addresses = new ArrayList JavaDoc();
31   
32   /**
33    * A unique id for this person. Note that the Digester automatically
34    * converts the id to an integer.
35    */

36   public void setId(int id) {
37       this.id = id;
38   }
39   
40   public void setCategory(String JavaDoc category) {
41       this.category = category;
42   }
43   
44   public void setName(String JavaDoc name) {
45       this.name = name;
46   }
47   
48   /** we assume only one email of each type... */
49   public void addEmail(String JavaDoc type, String JavaDoc address) {
50       emails.put(type, address);
51   }
52   
53   public void addAddress( Address addr ) {
54      addresses.add( addr );
55   }
56
57   public void print() {
58       System.out.println("Person #" + id);
59       System.out.println(" category=" + category);
60       System.out.println(" name=" + name);
61       
62       for(Iterator JavaDoc i = emails.keySet().iterator(); i.hasNext(); ) {
63           String JavaDoc type = (String JavaDoc) i.next();
64           String JavaDoc address = (String JavaDoc) emails.get(type);
65           
66           System.out.println(" email (type " + type + ") : " + address);
67       }
68       
69       for(Iterator JavaDoc i = addresses.iterator(); i.hasNext(); ) {
70           Address addr = (Address) i.next();
71           addr.print(System.out, 2);
72       }
73   }
74 }
75
Popular Tags