Started creating the booking interface for the owners.
[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         public Vector<Offer> offers;
18         public 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
86
87         @Override
88         public boolean equals(Object obj) {
89                 if (this == obj)
90                         return true;
91                 if (obj == null)
92                         return false;
93                 if (getClass() != obj.getClass())
94                         return false;
95                 RuralHouse other = (RuralHouse) obj;
96                 if (houseName == null) {
97                         if (other.houseName != null)
98                                 return false;
99                 } else if (!houseName.equals(other.houseName))
100                         return false;
101                 return true;
102         }
103
104         /**
105          * This method obtains available offers for a concrete house in a certain
106          * period
107          * 
108          * @param houseName
109          *            , the house number where the offers must be obtained
110          * @param firstDay
111          *            , first day in a period range
112          * @param lastDay
113          *            , last day in a period range
114          * @return a vector of offers(Offer class) available in this period
115          */
116         public Vector<Offer> getOffers(Date firstDay, Date lastDay) {
117                 Vector<Offer> availableOffers = new Vector<Offer>();
118                 Iterator<Offer> e = offers.iterator();
119                 Offer offer;
120                 while (e.hasNext()) {
121                         offer = e.next();
122                         if ((offer.getFirstDay().compareTo(firstDay) >= 0)
123                                         && (offer.getLastDay().compareTo(lastDay) <= 0)
124                                         && (offer.getBooking() == null))
125                                 availableOffers.add(offer);
126                 }
127                 return availableOffers;
128         }
129
130         public Vector<Offer> getAllOffers() {
131                 Vector<Offer> availableOffers = new Vector<Offer>();
132                 Iterator<Offer> e = offers.iterator();
133                 Offer offer;
134                 while (e.hasNext()) {
135                         offer = e.next();
136                         if ((offer.getBooking() == null))
137                                 availableOffers.add(offer);
138                 }
139                 return availableOffers;
140         }
141
142         /**
143          * This method obtains the offer that match exactly with a given dates that
144          * has not been booked
145          * 
146          * @param firstDay
147          *            , first day in a period range
148          * @param lastDay
149          *            , last day in a period range
150          * @return the offer(Offer class) available for a this period
151          */
152         public Offer findOffer(Date firstDay, Date lastDay) {
153                 Iterator<Offer> e = offers.iterator();
154                 Offer offer = null;
155                 while (e.hasNext()) {
156                         offer = e.next();
157                         if ((offer.getFirstDay().compareTo(firstDay) == 0)
158                                         && (offer.getLastDay().compareTo(lastDay) == 0)
159                                         && (offer.getBooking() == null))
160                                 return offer;
161                 }
162                 return null;
163         }
164
165         public Offer overlapsWith(Date firstDay, Date lastDay) {
166
167                 Iterator<Offer> e = offers.iterator();
168                 Offer offer = null;
169                 while (e.hasNext()) {
170                         offer = e.next();
171                         if ((offer.getFirstDay().compareTo(lastDay) < 0)
172                                         && (offer.getLastDay().compareTo(firstDay) > 0))
173                                 return offer;
174                 }
175                 return null;
176
177         }
178
179
180 }