Started with the separated DB with the given code
[RRRRHHHH_Code] / ruralHousesDB / 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
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         @Override
86         public boolean equals(Object obj) {
87                 if (this == obj)
88                         return true;
89                 if (obj == null)
90                         return false;
91                 if (getClass() != obj.getClass())
92                         return false;
93                 RuralHouse other = (RuralHouse) obj;
94                 if (houseName == null) {
95                         if (other.houseName != null)
96                                 return false;
97                 } else if (!houseName.equals(other.houseName))
98                         return false;
99                 return true;
100         }
101
102
103
104         public Offer overlapsWith(Date firstDay, Date lastDay) {
105
106                 Iterator<Offer> e = offers.iterator();
107                 Offer offer = null;
108                 while (e.hasNext()) {
109                         offer = e.next();
110                         if ((offer.getFirstDay().compareTo(lastDay) < 0)
111                                         && (offer.getLastDay().compareTo(firstDay) > 0))
112                                 return offer;
113                 }
114                 return null;
115
116         }
117         
118
119         public Vector<Offer> getAllOffers() {
120
121                 return this.offers;
122         }
123
124
125 }