7087a6688c39056761ffc368d84a8c4599d32f7c
[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 int houseNumber;
13         private String description;
14         private Owner owner;
15         private String town; 
16         private HouseFeatures features;
17         public Vector<Offer> offers;
18         
19         public RuralHouse() {
20                 super();
21         }
22
23         public RuralHouse(int houseNumber, Owner owner, String description, String town ,HouseFeatures features) {
24                 this.houseNumber = houseNumber;
25                 this.description = description;
26                 this.owner = owner;
27                 this.town = town;
28                 this.features = features;
29                 offers=new Vector<Offer>();
30         }
31         
32         
33
34         public int getHouseNumber() {
35                 return houseNumber;
36         }
37
38         public void setHouseNumber(int houseNumber) {
39                 this.houseNumber = houseNumber;
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 getTown() {
59                 return town;
60         }
61         
62         public void setTown(String town) {
63                 this.town=town;
64         }
65         public HouseFeatures getFeatures() {
66                 return features;
67         }
68
69         public void setFeatures(HouseFeatures features) {
70                 this.features = features;
71         }       
72         public String toString() {
73                 return this.houseNumber + ": " + this.town;
74         }
75         
76         public Offer createOffer(Date firstDay, Date lastDay, float price) {
77         Offer off=new Offer(this, firstDay, lastDay, price);
78         offers.add(off);
79         return off;
80         }
81
82         @Override
83         public int hashCode() {
84                 final int prime = 31;
85                 int result = 1;
86                 result = prime * result + houseNumber;
87                 return result;
88         }
89
90         @Override
91         public boolean equals(Object obj) {
92                 if (this == obj)
93                         return true;
94                 if (obj == null)
95                         return false;
96                 if (getClass() != obj.getClass())
97                         return false;
98                 RuralHouse other = (RuralHouse) obj;
99                 if (houseNumber != other.houseNumber)
100                         return false;
101                 return true;
102         }
103         
104         public String getAccountNumber(int houseNumber) {
105                 /*try {
106                         dbMngr=DBManager.getInstance();
107                         return dbMngr.getOwner(houseNumber).getBankAccount();
108
109                 } catch (Exception e) {
110                         System.out.println("Error, accessing to DB Manager: "
111                                         + e.toString());
112                         return null;
113                 }*/ return null;
114         }
115         
116         /**
117          * This method obtains available offers for a concrete house in a certain period 
118          * 
119          * @param houseNumber, the house number where the offers must be obtained 
120          * @param firstDay, first day in a period range 
121          * @param lastDay, last day in a period range
122          * @return a vector of offers(Offer class)  available  in this period
123          */
124         public Vector<Offer> getOffers( Date firstDay,  Date lastDay) {
125                 Vector<Offer> availableOffers=new Vector<Offer>();
126                 Iterator<Offer> e=offers.iterator();
127                 Offer offer;
128                 while (e.hasNext()){
129                         offer=e.next();
130                         if ( (offer.getFirstDay().compareTo(firstDay)>=0) && (offer.getLastDay().compareTo(lastDay)<=0) && (offer.getBooking()==null) )
131                                 availableOffers.add(offer);
132                 }
133                 return availableOffers;
134         }
135         
136         
137         /**
138          * This method obtains the offer that match exactly with a given dates that has not been booked
139          * 
140          * @param firstDay, first day in a period range 
141          * @param lastDay, last day in a period range
142          * @return the  offer(Offer class)  available  for a this period
143          */
144         public Offer findOffer( Date firstDay,  Date lastDay) {         
145                 Iterator<Offer> e=offers.iterator();
146                 Offer offer=null;
147                 while (e.hasNext()){
148                         offer=e.next();
149                         if ( (offer.getFirstDay().compareTo(firstDay)==0) && (offer.getLastDay().compareTo(lastDay)==0) && (offer.getBooking()==null) )
150                                 return offer;
151                 }
152                 return null;            
153         }
154         
155         
156
157 }