KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > tutorial > pobjects > additional > queries > Person


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  */

25
26 package org.objectweb.speedo.tutorial.pobjects.additional.queries;
27
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31
32 /**
33  * @author Y.Bersihand
34  */

35 public class Person {
36
37     private String JavaDoc name;
38     private Set JavaDoc children;
39     private int age;
40     private ContactDetails contactDetails;
41
42     public Person(String JavaDoc name, int age, ContactDetails contactDetails) {
43         this.name = name;
44         this.age = age;
45         this.children = new HashSet JavaDoc();
46         this.contactDetails = contactDetails;
47     }
48     
49     public Person(String JavaDoc name, String JavaDoc type, int age, ContactDetails contactDetails) {
50         this.name = name;
51         this.age = age;
52         this.children = new HashSet JavaDoc();
53         this.contactDetails = contactDetails;
54     }
55
56     public Person(String JavaDoc name, Set JavaDoc children, String JavaDoc type, int age, ContactDetails contactDetails){
57         this.name = name;
58         this.age = age;
59         this.children = children;
60         this.contactDetails = contactDetails;
61     }
62     
63     public Set JavaDoc getChildren() {
64         return children;
65     }
66     public void setChildren(Set JavaDoc children) {
67         this.children = children;
68     }
69     public String JavaDoc getName() {
70         return name;
71     }
72     public void setName(String JavaDoc name) {
73         this.name = name;
74     }
75     
76     public void addChild(Person p){
77         if(children == null){
78             children = new HashSet JavaDoc();
79         }
80         children.add(p);
81     }
82     
83     public int getAge() {
84         return age;
85     }
86     public void setAge(int age) {
87         this.age = age;
88     }
89         
90     public ContactDetails getContactDetails() {
91         return contactDetails;
92     }
93     public void setContactDetails(ContactDetails contactDetails) {
94         this.contactDetails = contactDetails;
95     }
96     
97     public String JavaDoc toString(){
98         String JavaDoc s = name + ", age=" + age + ", children=[";
99         Iterator JavaDoc it = children.iterator();
100         while(it.hasNext()){
101             Person p = (Person) it.next();
102             s += p.getName() + ", ";
103         }
104         if(!children.isEmpty())
105             s = s.substring(0, s.length()-2);
106         s += "]";
107         s += ", contact details=[" + contactDetails.toString() + "]";
108         return s;
109     }
110 }
111
Popular Tags