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