1 25 26 package org.objectweb.speedo.tutorial.pobjects.additional.queries; 27 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.Set ; 31 32 35 public class Person { 36 37 private String name; 38 private Set children; 39 private int age; 40 private ContactDetails contactDetails; 41 42 public Person(String name, int age, ContactDetails contactDetails) { 43 this.name = name; 44 this.age = age; 45 this.children = new HashSet (); 46 this.contactDetails = contactDetails; 47 } 48 49 public Person(String name, String type, int age, ContactDetails contactDetails) { 50 this.name = name; 51 this.age = age; 52 this.children = new HashSet (); 53 this.contactDetails = contactDetails; 54 } 55 56 public Person(String name, Set children, String 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 getChildren() { 64 return children; 65 } 66 public void setChildren(Set children) { 67 this.children = children; 68 } 69 public String getName() { 70 return name; 71 } 72 public void setName(String name) { 73 this.name = name; 74 } 75 76 public void addChild(Person p){ 77 if(children == null){ 78 children = new HashSet (); 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 toString(){ 98 String s = name + ", age=" + age + ", children=["; 99 Iterator 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 |