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 public Vector<Offer> offers;
22 public RuralHouse(int houseNumber, Owner owner, String description, String town) {
23 this.houseNumber = houseNumber;
24 this.description = description;
27 offers=new Vector<Offer>();
30 public int getHouseNumber() {
34 public void setHouseNumber(int houseNumber) {
35 this.houseNumber = houseNumber;
38 public String getDescription() {
42 public void setDescription(String description) {
43 this.description=description;
46 public Owner getOwner() {
50 public void setOwner(Owner owner) {
54 public String getTown() {
58 public void setTown(String town) {
62 public String toString() {
63 return this.houseNumber + ": " + this.town;
66 public Offer createOffer(Date firstDay, Date lastDay, float price) {
67 Offer off=new Offer(this, firstDay, lastDay, price);
73 public int hashCode() {
76 result = prime * result + houseNumber;
81 public boolean equals(Object obj) {
86 if (getClass() != obj.getClass())
88 RuralHouse other = (RuralHouse) obj;
89 if (houseNumber != other.houseNumber)
94 public String getAccountNumber(int houseNumber) {
96 dbMngr=DBManager.getInstance();
97 return dbMngr.getOwner(houseNumber).getBankAccount();
99 } catch (Exception e) {
100 System.out.println("Error, accessing to DB Manager: "
107 * This method obtains available offers for a concrete house in a certain period
109 * @param houseNumber, the house number where the offers must be obtained
110 * @param firstDay, first day in a period range
111 * @param lastDay, last day in a period range
112 * @return a vector of offers(Offer class) available in this period
114 public Vector<Offer> getOffers( Date firstDay, Date lastDay) {
115 Vector<Offer> availableOffers=new Vector<Offer>();
116 Iterator<Offer> e=offers.iterator();
120 if ( (offer.getFirstDay().compareTo(firstDay)>=0) && (offer.getLastDay().compareTo(lastDay)<=0) && (offer.getBooking()==null) )
121 availableOffers.add(offer);
123 return availableOffers;
127 * This method obtains the offer that match exactly with a given dates that has not been booked
129 * @param firstDay, first day in a period range
130 * @param lastDay, last day in a period range
131 * @return the offer(Offer class) available for a this period
133 public Offer findOffer( Date firstDay, Date lastDay) {
134 Iterator<Offer> e=offers.iterator();
138 if ( (offer.getFirstDay().compareTo(firstDay)==0) && (offer.getLastDay().compareTo(lastDay)==0) && (offer.getBooking()==null) )