1 17 18 package org.apache.commons.digester; 19 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 24 25 28 29 public class Employee { 30 31 public Employee() { 32 this("My First Name", "My Last Name"); 33 } 34 35 public Employee(String firstName, String lastName) { 36 super(); 37 setFirstName(firstName); 38 setLastName(lastName); 39 } 40 41 private ArrayList addresses = new ArrayList (); 42 43 public void addAddress(Address address) { 44 addresses.add(address); 45 } 46 47 public Address getAddress(String type) { 48 Iterator elements = addresses.iterator(); 49 while (elements.hasNext()) { 50 Address element = (Address) elements.next(); 51 if (type.equals(element.getType())) 52 return (element); 53 } 54 return (null); 55 } 56 57 public void removeAddress(Address address) { 58 addresses.remove(address); 59 } 60 61 private String firstName = null; 62 63 public String getFirstName() { 64 return (this.firstName); 65 } 66 67 public void setFirstName(String firstName) { 68 this.firstName = firstName; 69 } 70 71 private String lastName = null; 72 73 public String getLastName() { 74 return (this.lastName); 75 } 76 77 public void setLastName(String lastName) { 78 this.lastName = lastName; 79 } 80 81 private int age; 83 private boolean active; 84 private float salary; 85 86 public int getAge() 87 { 88 return age; 89 } 90 91 public void setAge(int age) 92 { 93 this.age = age; 94 } 95 96 public boolean isActive() 97 { 98 return active; 99 } 100 101 public void setActive(boolean active) 102 { 103 this.active = active; 104 } 105 106 public float getSalary() 107 { 108 return salary; 109 } 110 111 public void setSalary(float salary) 112 { 113 this.salary = salary; 114 } 115 116 public String toString() { 117 StringBuffer sb = new StringBuffer ("Employee["); 118 sb.append("firstName="); 119 sb.append(firstName); 120 sb.append(", lastName="); 121 sb.append(lastName); 122 sb.append("]"); 123 return (sb.toString()); 124 } 125 126 } 127 | Popular Tags |