3 import java.io.Serializable;
5 import java.util.Iterator;
6 import java.util.Vector;
8 public class RuralHouse implements Serializable {
10 private static final long serialVersionUID = 1L;
12 private int houseNumber;
13 private String description;
16 private HouseFeatures features;
17 public Vector<Offer> offers;
23 public RuralHouse(int houseNumber, Owner owner, String description, String town ,HouseFeatures features) {
24 this.houseNumber = houseNumber;
25 this.description = description;
28 this.features = features;
29 offers=new Vector<Offer>();
34 public int getHouseNumber() {
38 public void setHouseNumber(int houseNumber) {
39 this.houseNumber = houseNumber;
42 public String getDescription() {
46 public void setDescription(String description) {
47 this.description=description;
50 public Owner getOwner() {
54 public void setOwner(Owner owner) {
58 public String getTown() {
62 public void setTown(String town) {
65 public HouseFeatures getFeatures() {
69 public void setFeatures(HouseFeatures features) {
70 this.features = features;
72 public String toString() {
73 return this.houseNumber + ": " + this.town;
76 public Offer createOffer(int offerNumber,Date firstDay, Date lastDay, float price) {
77 Offer off=new Offer(offerNumber,this,firstDay,lastDay,price);
84 public int hashCode() {
87 result = prime * result + houseNumber;
92 public boolean equals(Object obj) {
97 if (getClass() != obj.getClass())
99 RuralHouse other = (RuralHouse) obj;
100 if (houseNumber != other.houseNumber)
105 public String getAccountNumber(int houseNumber) {
107 dbMngr=DBManager.getInstance();
108 return dbMngr.getOwner(houseNumber).getBankAccount();
110 } catch (Exception e) {
111 System.out.println("Error, accessing to DB Manager: "
118 * This method obtains available offers for a concrete house in a certain period
120 * @param houseNumber, the house number where the offers must be obtained
121 * @param firstDay, first day in a period range
122 * @param lastDay, last day in a period range
123 * @return a vector of offers(Offer class) available in this period
125 public Vector<Offer> getOffers( Date firstDay, Date lastDay) {
126 Vector<Offer> availableOffers=new Vector<Offer>();
127 Iterator<Offer> e=offers.iterator();
131 if ( (offer.getFirstDay().compareTo(firstDay)>=0) && (offer.getLastDay().compareTo(lastDay)<=0) && (offer.getBooking()==null) )
132 availableOffers.add(offer);
134 return availableOffers;
139 * This method obtains the offer that match exactly with a given dates that has not been booked
141 * @param firstDay, first day in a period range
142 * @param lastDay, last day in a period range
143 * @return the offer(Offer class) available for a this period
145 public Offer findOffer( Date firstDay, Date lastDay) {
146 Iterator<Offer> e=offers.iterator();
150 if ( (offer.getFirstDay().compareTo(firstDay)==0) && (offer.getLastDay().compareTo(lastDay)==0) && (offer.getBooking()==null) )
156 public Offer overlapsWith( Date firstDay, Date lastDay) {
158 Iterator<Offer> e=offers.iterator();
162 if ( (offer.getFirstDay().compareTo(lastDay)<0) && (offer.getLastDay().compareTo(firstDay)>0))