house code changed to name
[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 town; 
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 town , HouseFeatures features) {
25                 this.houseName = houseName;
26                 this.description = description;
27                 this.owner = owner;
28                 this.town = town;
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 getTown() {
60                 return town;
61         }
62         
63         public void setTown(String town) {
64                 this.town=town;
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.town;
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         public String getAccountNumber(int houseName) {
102                 /*try {
103                         dbMngr=DBManager.getInstance();
104                         return dbMngr.getOwner(houseName).getBankAccount();
105
106                 } catch (Exception e) {
107                         System.out.println("Error, accessing to DB Manager: "
108                                         + e.toString());
109                         return null;
110                 }*/ return null;
111         }
112         
113         /**
114          * This method obtains available offers for a concrete house in a certain period 
115          * 
116          * @param houseName, the house number where the offers must be obtained 
117          * @param firstDay, first day in a period range 
118          * @param lastDay, last day in a period range
119          * @return a vector of offers(Offer class)  available  in this period
120          */
121         public Vector<Offer> getOffers( Date firstDay,  Date lastDay) {
122                 Vector<Offer> availableOffers=new Vector<Offer>();
123                 Iterator<Offer> e=offers.iterator();
124                 Offer offer;
125                 while (e.hasNext()){
126                         offer=e.next();
127                         if ( (offer.getFirstDay().compareTo(firstDay)>=0) && (offer.getLastDay().compareTo(lastDay)<=0) && (offer.getBooking()==null) )
128                                 availableOffers.add(offer);
129                 }
130                 return availableOffers;
131         }
132         
133         
134         /**
135          * This method obtains the offer that match exactly with a given dates that has not been booked
136          * 
137          * @param firstDay, first day in a period range 
138          * @param lastDay, last day in a period range
139          * @return the  offer(Offer class)  available  for a this period
140          */
141         public Offer findOffer( Date firstDay,  Date lastDay) {         
142                 Iterator<Offer> e=offers.iterator();
143                 Offer offer=null;
144                 while (e.hasNext()){
145                         offer=e.next();
146                         if ( (offer.getFirstDay().compareTo(firstDay)==0) && (offer.getLastDay().compareTo(lastDay)==0) && (offer.getBooking()==null) )
147                                 return offer;
148                 }
149                 return null;            
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) && (offer.getLastDay().compareTo(firstDay)>0))
159                                 return offer;
160                 }
161                 return null;
162                 
163         }
164
165 }