Some improvements done, owner deletion started, some bugs remain there
[RRRRHHHH_Code] / ruralHouses / src / domain / RuralHouse.java
1 package domain;
2
3 import java.io.Serializable;
4 import java.util.Date;
5 import java.util.Iterator;
6 import java.util.Vector;
7
8 public class RuralHouse implements Serializable {
9
10         private static final long serialVersionUID = 1L;
11
12         private String houseName;
13         private String description;
14         private Owner owner;
15         private String district;
16         private HouseFeatures features;
17         private Vector<Offer> offers;
18         private boolean isAccepted;
19
20         public RuralHouse() {
21                 super();
22         }
23
24         public RuralHouse(String houseName, Owner owner, String description,
25                         String ds, HouseFeatures features) {
26                 this.houseName = houseName;
27                 this.description = description;
28                 this.owner = owner;
29                 this.district = ds;
30                 this.features = features;
31                 offers = new Vector<Offer>();
32         }
33
34         public String getHouseName() {
35                 return houseName;
36         }
37
38         public void setHouseName(String houseName) {
39                 this.houseName = houseName;
40         }
41
42         public String getDescription() {
43                 return description;
44         }
45
46         public void setDescription(String description) {
47                 this.description = description;
48         }
49
50         public Owner getOwner() {
51                 return owner;
52         }
53
54         public void setOwner(Owner owner) {
55                 this.owner = owner;
56         }
57
58         public String getDistrict() {
59                 return district;
60         }
61
62         public void setDistrict(String ds) {
63                 this.district = ds;
64         }
65
66         public HouseFeatures getFeatures() {
67                 return features;
68         }
69
70         public void setFeatures(HouseFeatures features) {
71                 this.features = features;
72         }
73
74         public String toString() {
75                 return this.houseName + ": " + this.district;
76         }
77
78         public Offer createOffer(int offerNumber, Date firstDay, Date lastDay,
79                         float price) {
80                 Offer off = new Offer(offerNumber, this, firstDay, lastDay, price);
81                 offers.add(off);
82                 return off;
83         }
84
85         @Override
86         public boolean equals(Object obj) {
87                 if (this == obj)
88                         return true;
89                 if (obj == null)
90                         return false;
91                 if (getClass() != obj.getClass())
92                         return false;
93                 RuralHouse other = (RuralHouse) obj;
94                 if (houseName == null) {
95                         if (other.houseName != null)
96                                 return false;
97                 } else if (!houseName.equals(other.houseName))
98                         return false;
99                 return true;
100         }
101
102         /**
103          * This method obtains available offers for a concrete house in a certain
104          * period
105          * 
106          * @param houseName
107          *            , the house number where the offers must be obtained
108          * @param firstDay
109          *            , first day in a period range
110          * @param lastDay
111          *            , last day in a period range
112          * @return a vector of offers(Offer class) available in this period
113          */
114         public Vector<Offer> getOffers(Date firstDay, Date lastDay) {
115                 Vector<Offer> availableOffers = new Vector<Offer>();
116                 Iterator<Offer> e = offers.iterator();
117                 Offer offer;
118                 while (e.hasNext()) {
119                         offer = e.next();
120                         if ((offer.getFirstDay().compareTo(firstDay) >= 0)
121                                         && (offer.getLastDay().compareTo(lastDay) <= 0)
122                                         && (!offer.isBooked()))
123                                 availableOffers.add(offer);
124                 }
125                 return availableOffers;
126         }
127
128         public Vector<Offer> getAllOffers() {
129
130                 return this.offers;
131         }
132
133         /**
134          * This method obtains the offer that match exactly with a given dates that
135          * has not been booked
136          * 
137          * @param firstDay
138          *            , first day in a period range
139          * @param lastDay
140          *            , last day in a period range
141          * @return the offer(Offer class) available for a this period
142          */
143         public Offer findOffer(Date firstDay, Date lastDay) {
144                 Iterator<Offer> e = offers.iterator();
145                 Offer offer = null;
146                 while (e.hasNext()) {
147                         offer = e.next();
148                         if ((offer.getFirstDay().compareTo(firstDay) == 0)
149                                         && (offer.getLastDay().compareTo(lastDay) == 0)
150                                         && (!offer.isBooked()))
151                                 return offer;
152                 }
153                 return null;
154         }
155
156         public Offer overlapsWith(Date firstDay, Date lastDay) {
157
158                 Iterator<Offer> e = offers.iterator();
159                 Offer offer = null;
160                 while (e.hasNext()) {
161                         offer = e.next();
162                         if ((offer.getFirstDay().compareTo(lastDay) < 0)
163                                         && (offer.getLastDay().compareTo(firstDay) > 0))
164                                 return offer;
165                 }
166                 return null;
167
168         }
169
170         public boolean isAccepted() {
171                 return isAccepted;
172         }
173
174         public void setAccepted(boolean isAccepted) {
175                 this.isAccepted = isAccepted;
176         }
177
178 }