1 package org.objectweb.rentacar.persistance.bo; 2 3 import java.util.HashSet ; 4 import java.util.Set ; 5 6 import org.apache.commons.lang.builder.EqualsBuilder; 7 import org.apache.commons.lang.builder.HashCodeBuilder; 8 import org.apache.commons.lang.builder.ToStringBuilder; 9 10 15 public class AgencyVO { 16 17 private String agencyId; 18 19 private String host; 20 21 private String port; 22 23 private String warName; 24 25 private ContactVO contact; 26 27 private Set <CarVO> cars; 28 29 public AgencyVO() { 30 super(); 31 } 32 33 public AgencyVO(ContactVO contact, Set <CarVO> cars, CentralOfficeVO centralOffice) { 34 super(); 35 this.contact = contact; 36 this.cars = cars; 37 } 38 39 public AgencyVO(String agencyId, ContactVO contact, Set <CarVO> cars, CentralOfficeVO centralOffice) { 40 super(); 41 this.agencyId = agencyId; 42 this.contact = contact; 43 this.cars = cars; 44 } 45 46 public AgencyVO(Agency agency) { 47 super(); 48 this.agencyId = agency.getAgencyId(); 49 this.contact = new ContactVO(agency.getContact()); 50 Set <CarVO> cars = new HashSet <CarVO>(); 51 for (Car car : agency.getCars()) { 52 cars.add(new CarVO(car)); 53 } 54 this.cars = cars; 55 this.host = agency.getHost(); 56 this.port = agency.getPort(); 57 this.warName = agency.getWarName(); 58 } 59 60 public String getAgencyId() { 61 return agencyId; 62 } 63 64 public void setAgencyId(String agencyId) { 65 this.agencyId = agencyId; 66 } 67 68 public Set <CarVO> getCars() { 69 return cars; 70 } 71 72 public void setCars(Set <CarVO> cars) { 73 this.cars = cars; 74 } 75 76 public ContactVO getContact() { 77 return contact; 78 } 79 80 public void setContact(ContactVO contact) { 81 this.contact = contact; 82 } 83 public int getNumberOfCarByType(String type){ 84 int maxNumberCarsOfType=0; 85 for (CarVO car : cars) { 86 if(car.getType().equals(type)) 87 maxNumberCarsOfType++; 88 } 89 return maxNumberCarsOfType; 90 } 91 92 public String getHost() { 93 return host; 94 } 95 96 public void setHost(String host) { 97 this.host = host; 98 } 99 100 public String getPort() { 101 return port; 102 } 103 104 public void setPort(String port) { 105 this.port = port; 106 } 107 108 public String getWarName() { 109 return warName; 110 } 111 112 public void setWarName(String warName) { 113 this.warName = warName; 114 } 115 116 119 public boolean equals(Object object) { 120 if (!(object instanceof AgencyVO)) { 121 return false; 122 } 123 AgencyVO rhs = (AgencyVO) object; 124 return new EqualsBuilder().append(this.contact, rhs.contact).append( 125 this.cars, rhs.cars).append(this.agencyId, rhs.agencyId) 126 .append(this.host, rhs.host).append(this.port, rhs.port) 127 .append(this.warName, rhs.warName).isEquals(); 128 } 129 130 133 public int hashCode() { 134 return new HashCodeBuilder(-1800697853, -175234907) 135 .append(this.contact).append(this.cars).append(this.agencyId) 136 .append(this.host).append(this.port).append(this.warName).toHashCode(); 137 } 138 139 142 public String toString() { 143 return new ToStringBuilder(this).append("host", this.host).append( 144 "agencyId", this.agencyId).append("contact", this.contact) 145 .append("port", this.port).append("cars", this.cars).append(this.warName).toString(); 146 } 147 } 148 | Popular Tags |