1 22 package org.jboss.test.cache.test.standAloneAop; 23 24 import java.util.*; 25 26 27 33 public class Person 34 { 35 String name = null; 36 int age = 0; 37 Map hobbies = null; 38 Address address = null; 39 Set skills; 40 List languages; 41 transient String currentStatus = "Active"; 43 List medication = null; 46 static final int AGE1 = 50; 47 static final int AGE2 = 60; 48 49 public Person() { 50 51 } 52 53 public String getName() 54 { 55 return name; 56 } 57 58 public void setName(String name) 59 { 60 this.name = name; 61 } 62 63 public void setCurrentStatus(String status) { 64 currentStatus = status; 65 } 66 67 public String getCurrentStatus() { 68 return currentStatus; 69 } 70 71 public void setName(Object obj) 72 { 73 this.name = (String )obj; 74 } 75 76 public int getAge() 77 { 78 return age; 79 } 80 81 public void setAge(int age) 82 { 83 84 this.age = age; 85 86 if(age < AGE1) { 88 if(medication != null) { 89 medication.clear(); 90 medication=null; 91 } 92 } 93 else { 94 if( age >= AGE1 ) { 95 addMedication("Lipitor"); 96 } 97 98 if (age >= AGE2) { 99 addMedication("Vioxx"); 100 } 101 } 102 103 104 } 105 106 void addMedication(String name) { 107 if( medication == null ) 108 medication = new ArrayList(); 109 if(!medication.contains(name)) 110 medication.add(name); 111 } 112 113 public Map getHobbies() 114 { 115 return hobbies; 116 } 117 118 public void setHobbies(Map hobbies) 119 { 120 this.hobbies = hobbies; 121 } 122 123 public Address getAddress() 124 { 125 return address; 126 } 127 128 public void setAddress(Address address) 129 { 130 this.address = address; 131 } 132 133 public Set getSkills() 134 { 135 return skills; 136 } 137 138 public void setSkills(Set skills) 139 { 140 this.skills = skills; 141 } 142 143 public List getMedication() 144 { 145 return medication; 146 } 147 148 public void setMedication(List medication) 149 { 150 this.medication = medication; 151 } 152 153 public List getLanguages() 154 { 155 return languages; 156 } 157 158 public void setLanguages(List languages) 159 { 160 this.languages = languages; 161 } 162 163 public String toString() 164 { 165 StringBuffer sb=new StringBuffer (); 166 sb.append("name=").append(getName()).append(", age=").append(getAge()).append(", hobbies=") 167 .append(print(getHobbies())).append(", address=").append(getAddress()).append(", skills=") 168 .append(skills).append(", languages=").append(languages).toString(); 169 if(medication != null) 170 sb.append(", medication=" + medication); 171 return sb.toString(); 172 } 173 174 public String print(Map m) 175 { 176 StringBuffer sb = new StringBuffer (); 177 Map.Entry entry; 178 if (m != null) { 179 for (Iterator it = m.entrySet().iterator(); it.hasNext();) { 180 entry = (Map.Entry) it.next(); 181 sb.append(entry.getKey()).append(": ").append(entry.getValue()); 182 sb.append("\n"); 183 } 184 } 185 return sb.toString(); 186 } 187 } 188 | Popular Tags |