081ef4cd8e9179a3040eb97946b16582b7da80bf
[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, String ds , HouseFeatures features) {
25                 this.houseName = houseName;
26                 this.description = description;
27                 this.owner = owner;
28                 this.district = ds;
29                 this.features = features;
30                 offers=new Vector<Offer>();
31         }
32         
33         
34
35         public String getHouseName() {
36                 return houseName;
37         }
38
39         public void setHouseName(String houseName) {
40                 this.houseName = houseName;
41         }
42
43         public String getDescription() {
44                 return description;
45         }
46         
47         public void setDescription(String description) {
48                 this.description=description;
49         }
50
51         public Owner getOwner() {
52                 return owner;
53         }
54
55         public void setOwner(Owner owner) {
56                 this.owner=owner;
57         }
58         
59         public String getDistrict() {
60                 return district;
61         }
62         
63         public void setDistrict(String ds) {
64                 this.district=ds;
65         }
66         public HouseFeatures getFeatures() {
67                 return features;
68         }
69
70         public void setFeatures(HouseFeatures features) {
71                 this.features = features;
72         }       
73         public String toString() {
74                 return this.houseName + ": " + this.district;
75         }
76         
77         public Offer createOffer(int offerNumber,Date firstDay, Date lastDay, float price)  {
78         Offer off=new Offer(offerNumber,this,firstDay,lastDay,price);
79         offers.add(off);
80         return off;
81         }
82
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 != other.houseName)
97                         return false;
98                 return true;
99         }
100
101         
102         /**
103          * This method obtains available offers for a concrete house in a certain period 
104          * 
105          * @param houseName, the house number where the offers must be obtained 
106          * @param firstDay, first day in a period range 
107          * @param lastDay, last day in a period range
108          * @return a vector of offers(Offer class)  available  in this period
109          */
110         public Vector<Offer> getOffers( Date firstDay,  Date lastDay) {
111                 Vector<Offer> availableOffers=new Vector<Offer>();
112                 Iterator<Offer> e=offers.iterator();
113                 Offer offer;
114                 while (e.hasNext()){
115                         offer=e.next();
116                         if ( (offer.getFirstDay().compareTo(firstDay)>=0) && (offer.getLastDay().compareTo(lastDay)<=0) && (offer.getBooking()==null) )
117                                 availableOffers.add(offer);
118                 }
119                 return availableOffers;
120         }
121         
122         public Vector<Offer> getAllOffers() {
123                 Vector<Offer> availableOffers=new Vector<Offer>();
124                 Iterator<Offer> e=offers.iterator();
125                 Offer offer;
126                 while (e.hasNext()){
127                         offer=e.next();
128                         if ( (offer.getBooking()==null) )
129                                 availableOffers.add(offer);
130                 }
131                 return availableOffers;
132         }
133         /**
134          * This method obtains the offer that match exactly with a given dates that has not been booked
135          * 
136          * @param firstDay, first day in a period range 
137          * @param lastDay, last day in a period range
138          * @return the  offer(Offer class)  available  for a this period
139          */
140         public Offer findOffer( Date firstDay,  Date lastDay) {         
141                 Iterator<Offer> e=offers.iterator();
142                 Offer offer=null;
143                 while (e.hasNext()){
144                         offer=e.next();
145                         if ( (offer.getFirstDay().compareTo(firstDay)==0) && (offer.getLastDay().compareTo(lastDay)==0) && (offer.getBooking()==null) )
146                                 return offer;
147                 }
148                 return null;            
149         }
150         
151         
152 public Offer overlapsWith( Date firstDay,  Date lastDay) {
153                 
154                 Iterator<Offer> e=offers.iterator();
155                 Offer offer=null;
156                 while (e.hasNext()){
157                         offer=e.next();
158                         if ( (offer.getFirstDay().compareTo(lastDay)<0) 
159                                         && (offer.getLastDay().compareTo(firstDay)>0))
160                                 return offer;
161                 }
162                 return null;
163                 
164         }
165
166 }