KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > persistance > bo > AgencyVO


1 package org.objectweb.rentacar.persistance.bo;
2
3 import java.util.HashSet JavaDoc;
4 import java.util.Set JavaDoc;
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 /**
11  *
12  * @author ofabre
13  *
14  */

15 public class AgencyVO {
16     
17     private String JavaDoc agencyId;
18     
19     private String JavaDoc host;
20     
21     private String JavaDoc port;
22     
23     private String JavaDoc warName;
24     
25     private ContactVO contact;
26     
27     private Set JavaDoc<CarVO> cars;
28
29     public AgencyVO() {
30         super();
31     }
32     
33     public AgencyVO(ContactVO contact, Set JavaDoc<CarVO> cars, CentralOfficeVO centralOffice) {
34         super();
35         this.contact = contact;
36         this.cars = cars;
37     }
38
39     public AgencyVO(String JavaDoc agencyId, ContactVO contact, Set JavaDoc<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 JavaDoc<CarVO> cars = new HashSet JavaDoc<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 JavaDoc getAgencyId() {
61         return agencyId;
62     }
63
64     public void setAgencyId(String JavaDoc agencyId) {
65         this.agencyId = agencyId;
66     }
67
68     public Set JavaDoc<CarVO> getCars() {
69         return cars;
70     }
71
72     public void setCars(Set JavaDoc<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 JavaDoc 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 JavaDoc getHost() {
93         return host;
94     }
95
96     public void setHost(String JavaDoc host) {
97         this.host = host;
98     }
99
100     public String JavaDoc getPort() {
101         return port;
102     }
103
104     public void setPort(String JavaDoc port) {
105         this.port = port;
106     }
107     
108     public String JavaDoc getWarName() {
109         return warName;
110     }
111
112     public void setWarName(String JavaDoc warName) {
113         this.warName = warName;
114     }
115
116     /**
117      * @see java.lang.Object#equals(Object)
118      */

119     public boolean equals(Object JavaDoc 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     /**
131      * @see java.lang.Object#hashCode()
132      */

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     /**
140      * @see java.lang.Object#toString()
141      */

142     public String JavaDoc 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