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