1 16 package org.apache.commons.betwixt; 17 18 import java.io.Serializable ; 19 import java.math.BigDecimal ; 20 import java.math.BigInteger ; 21 import java.sql.Date ; 22 import java.sql.Time ; 23 import java.sql.Timestamp ; 24 import java.util.ArrayList ; 25 import java.util.Enumeration ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 39 public class CustomerBean implements Serializable { 40 41 42 private static final Log log = LogFactory.getLog( CustomerBean.class ); 43 44 private String id; 45 private String name; 46 private String nickName; 47 private String [] emails; 48 private int[] numbers; 49 private AddressBean address; 50 private Map projectMap; 51 private List locations = new ArrayList (); 52 private Date date; 53 private Time time; 54 private Timestamp timestamp; 55 private BigDecimal bigDecimal; 56 private BigInteger bigInteger; 57 58 public CustomerBean() { 59 } 60 61 public String getID() { 62 return id; 63 } 64 65 public String getNickName() { 66 return nickName; 67 } 68 69 70 public String getName() { 71 return name; 72 } 73 74 public String [] getEmails() { 75 return emails; 76 } 77 78 public int[] getNumbers() { 79 return numbers; 80 } 81 82 public AddressBean getAddress() { 83 return address; 84 } 85 86 public Map getProjectMap() { 87 return projectMap; 88 } 89 90 public Iterator getProjectNames() { 91 if ( projectMap == null ) { 92 return null; 93 } 94 return projectMap.keySet().iterator(); 95 } 96 97 public Enumeration getProjectURLs() { 98 if ( projectMap == null ) { 99 return null; 100 } 101 return new IteratorEnumeration( projectMap.values().iterator() ); 102 } 103 104 public List getLocations() { 105 return locations; 106 } 107 108 109 public String getLocation(int index) { 110 return (String ) locations.get(index); 111 } 112 113 public void setID(String id) { 114 this.id = id; 115 } 116 117 public void setName(String name) { 118 this.name = name; 119 } 120 121 public void setNickName(String nickName) { 122 this.nickName = nickName; 123 } 124 125 public void setEmails(String [] emails) { 126 this.emails = emails; 127 } 128 129 public void addEmail(String email) { 130 int newLength = (emails == null) ? 1 : emails.length+1; 131 String [] newArray = new String [newLength]; 132 for (int i=0; i< newLength-1; i++) { 133 newArray[i] = emails[i]; 134 } 135 newArray[newLength-1] = email; 136 emails = newArray; 137 } 138 139 public void setNumbers(int[] numbers) { 140 this.numbers = numbers; 141 } 142 143 public void addNumber(int number) { 144 if ( log.isDebugEnabled() ) { 145 log.debug( "Adding number: " + number ); 146 } 147 148 int newLength = (numbers == null) ? 1 : numbers.length+1; 149 int[] newArray = new int[newLength]; 150 for (int i=0; i< newLength-1; i++) { 151 newArray[i] = numbers[i]; 152 } 153 newArray[newLength-1] = number; 154 numbers = newArray; 155 } 156 157 public void setAddress(AddressBean address) { 158 this.address = address; 159 160 if ( log.isDebugEnabled() ) { 161 log.debug( "Setting the address to be: " + address ); 162 } 163 } 164 165 public void setProjectMap(Map projectMap) { 166 this.projectMap = projectMap; 167 } 168 169 public void addLocation(String location) { 170 locations.add(location); 171 } 172 173 174 public void setLocation(int index, String location) { 175 if ( index == locations.size() ) { 176 locations.add( location ); 177 } 178 else { 179 locations.set(index, location); 180 } 181 } 182 183 public String toString() { 184 return "[" + this.getClass().getName() + ": ID=" + id + ", name=" + name 185 + ", address=" + address + "]"; 186 } 187 188 public boolean equals( Object obj ) { 189 if ( obj == null ) return false; 190 return this.hashCode() == obj.hashCode(); 191 } 192 193 public int hashCode() { 194 return toString().hashCode(); 195 } 196 200 public Date getDate() { 201 return date; 202 } 203 204 208 public Time getTime() { 209 return time; 210 } 211 212 216 public Timestamp getTimestamp() { 217 return timestamp; 218 } 219 220 224 public void setDate(Date date) { 225 this.date = date; 226 } 227 228 232 public void setTime(Time time) { 233 this.time = time; 234 } 235 236 240 public void setTimestamp(Timestamp timestamp) { 241 this.timestamp = timestamp; 242 } 243 244 248 public BigDecimal getBigDecimal() { 249 return bigDecimal; 250 } 251 252 256 public BigInteger getBigInteger() { 257 return bigInteger; 258 } 259 260 264 public void setBigDecimal(BigDecimal bigDecimal) { 265 this.bigDecimal = bigDecimal; 266 } 267 268 272 public void setBigInteger(BigInteger bigInteger) { 273 this.bigInteger = bigInteger; 274 } 275 276 283 private static final class IteratorEnumeration implements Enumeration { 284 285 286 private Iterator iterator; 287 288 293 public IteratorEnumeration() { 294 super(); 295 } 296 297 303 public IteratorEnumeration( Iterator iterator ) { 304 super(); 305 this.iterator = iterator; 306 } 307 308 311 316 public boolean hasMoreElements() { 317 return iterator.hasNext(); 318 } 319 320 327 public Object nextElement() { 328 return iterator.next(); 329 } 330 331 334 339 public Iterator getIterator() { 340 return iterator; 341 } 342 343 348 public void setIterator( Iterator iterator ) { 349 this.iterator = iterator; 350 } 351 352 } 353 354 355 } 356 | Popular Tags |