Skip to content

Commit 5de2a59

Browse files
committed
Polish
1 parent 9d27aa2 commit 5de2a59

File tree

14 files changed

+695
-704
lines changed

14 files changed

+695
-704
lines changed

booking-faces/src/main/java/org/springframework/webflow/samples/booking/Booking.java

Lines changed: 170 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -30,197 +30,197 @@
3030
@Entity
3131
public class Booking implements Serializable {
3232

33-
private static final long serialVersionUID = 1171567558348174963L;
33+
private static final long serialVersionUID = 1171567558348174963L;
3434

35-
private Long id;
35+
private Long id;
3636

37-
private User user;
37+
private User user;
3838

39-
private Hotel hotel;
39+
private Hotel hotel;
4040

41-
private Date checkinDate;
41+
private Date checkinDate;
4242

43-
private Date checkoutDate;
43+
private Date checkoutDate;
4444

45-
private String creditCard;
45+
private String creditCard;
4646

47-
private String creditCardName;
47+
private String creditCardName;
4848

49-
private int creditCardExpiryMonth;
49+
private int creditCardExpiryMonth;
5050

51-
private int creditCardExpiryYear;
51+
private int creditCardExpiryYear;
5252

53-
private boolean smoking;
53+
private boolean smoking;
5454

55-
private int beds;
55+
private int beds;
5656

57-
private Amenity[] amenities;
57+
private Amenity[] amenities;
5858

59-
public Booking() {
60-
}
59+
public Booking() {
60+
}
61+
62+
public Booking(Hotel hotel, User user) {
63+
this.hotel = hotel;
64+
this.user = user;
65+
Calendar calendar = Calendar.getInstance();
66+
calendar.add(Calendar.DAY_OF_MONTH, 1);
67+
setCheckinDate(calendar.getTime());
68+
calendar.add(Calendar.DAY_OF_MONTH, 1);
69+
setCheckoutDate(calendar.getTime());
70+
}
71+
72+
@Transient
73+
public BigDecimal getTotal() {
74+
return hotel.getPrice().multiply(new BigDecimal(getNights()));
75+
}
76+
77+
@Transient
78+
public int getNights() {
79+
if (checkinDate == null || checkoutDate == null) {
80+
return 0;
81+
} else {
82+
return (int) (checkoutDate.getTime() - checkinDate.getTime()) / 1000 / 60 / 60 / 24;
83+
}
84+
}
85+
86+
@Id
87+
@GeneratedValue(strategy = GenerationType.TABLE)
88+
public Long getId() {
89+
return id;
90+
}
91+
92+
public void setId(Long id) {
93+
this.id = id;
94+
}
95+
96+
@Basic
97+
@Temporal(TemporalType.DATE)
98+
@Future
99+
@NotNull
100+
public Date getCheckinDate() {
101+
return checkinDate;
102+
}
103+
104+
public void setCheckinDate(Date datetime) {
105+
this.checkinDate = datetime;
106+
}
107+
108+
@ManyToOne
109+
public Hotel getHotel() {
110+
return hotel;
111+
}
112+
113+
public void setHotel(Hotel hotel) {
114+
this.hotel = hotel;
115+
}
116+
117+
@ManyToOne
118+
public User getUser() {
119+
return user;
120+
}
121+
122+
public void setUser(User user) {
123+
this.user = user;
124+
}
125+
126+
@Basic
127+
@Temporal(TemporalType.DATE)
128+
@Future
129+
@NotNull
130+
public Date getCheckoutDate() {
131+
return checkoutDate;
132+
}
133+
134+
public void setCheckoutDate(Date checkoutDate) {
135+
this.checkoutDate = checkoutDate;
136+
}
61137

62-
public Booking(Hotel hotel, User user) {
63-
this.hotel = hotel;
64-
this.user = user;
65-
Calendar calendar = Calendar.getInstance();
66-
calendar.add(Calendar.DAY_OF_MONTH, 1);
67-
setCheckinDate(calendar.getTime());
68-
calendar.add(Calendar.DAY_OF_MONTH, 1);
69-
setCheckoutDate(calendar.getTime());
70-
}
138+
@Pattern(regexp = "[0-9]{16}", message = "{invalidCreditCardPattern}")
139+
public String getCreditCard() {
140+
return creditCard;
141+
}
142+
143+
public void setCreditCard(String creditCard) {
144+
this.creditCard = creditCard;
145+
}
146+
147+
@Transient
148+
public String getDescription() {
149+
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
150+
return hotel == null ? null : hotel.getName() + ", " + df.format(getCheckinDate()) + " to "
151+
+ df.format(getCheckoutDate());
152+
}
153+
154+
public boolean isSmoking() {
155+
return smoking;
156+
}
71157

72-
@Transient
73-
public BigDecimal getTotal() {
74-
return hotel.getPrice().multiply(new BigDecimal(getNights()));
75-
}
158+
public void setSmoking(boolean smoking) {
159+
this.smoking = smoking;
160+
}
76161

77-
@Transient
78-
public int getNights() {
79-
if (checkinDate == null || checkoutDate == null) {
80-
return 0;
81-
} else {
82-
return (int) (checkoutDate.getTime() - checkinDate.getTime()) / 1000 / 60 / 60 / 24;
162+
public int getBeds() {
163+
return beds;
83164
}
84-
}
85165

86-
@Id
87-
@GeneratedValue(strategy = GenerationType.TABLE)
88-
public Long getId() {
89-
return id;
90-
}
166+
public void setBeds(int beds) {
167+
this.beds = beds;
168+
}
91169

92-
public void setId(Long id) {
93-
this.id = id;
94-
}
170+
@NotEmpty
171+
public String getCreditCardName() {
172+
return creditCardName;
173+
}
95174

96-
@Basic
97-
@Temporal(TemporalType.DATE)
98-
@Future
99-
@NotNull
100-
public Date getCheckinDate() {
101-
return checkinDate;
102-
}
175+
public void setCreditCardName(String creditCardName) {
176+
this.creditCardName = creditCardName;
177+
}
103178

104-
public void setCheckinDate(Date datetime) {
105-
this.checkinDate = datetime;
106-
}
179+
public int getCreditCardExpiryMonth() {
180+
return creditCardExpiryMonth;
181+
}
182+
183+
public void setCreditCardExpiryMonth(int creditCardExpiryMonth) {
184+
this.creditCardExpiryMonth = creditCardExpiryMonth;
185+
}
107186

108-
@ManyToOne
109-
public Hotel getHotel() {
110-
return hotel;
111-
}
112-
113-
public void setHotel(Hotel hotel) {
114-
this.hotel = hotel;
115-
}
116-
117-
@ManyToOne
118-
public User getUser() {
119-
return user;
120-
}
121-
122-
public void setUser(User user) {
123-
this.user = user;
124-
}
125-
126-
@Basic
127-
@Temporal(TemporalType.DATE)
128-
@Future
129-
@NotNull
130-
public Date getCheckoutDate() {
131-
return checkoutDate;
132-
}
133-
134-
public void setCheckoutDate(Date checkoutDate) {
135-
this.checkoutDate = checkoutDate;
136-
}
137-
138-
@Pattern(regexp = "[0-9]{16}", message = "{invalidCreditCardPattern}")
139-
public String getCreditCard() {
140-
return creditCard;
141-
}
142-
143-
public void setCreditCard(String creditCard) {
144-
this.creditCard = creditCard;
145-
}
146-
147-
@Transient
148-
public String getDescription() {
149-
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
150-
return hotel == null ? null : hotel.getName() + ", " + df.format(getCheckinDate()) + " to "
151-
+ df.format(getCheckoutDate());
152-
}
153-
154-
public boolean isSmoking() {
155-
return smoking;
156-
}
157-
158-
public void setSmoking(boolean smoking) {
159-
this.smoking = smoking;
160-
}
161-
162-
public int getBeds() {
163-
return beds;
164-
}
165-
166-
public void setBeds(int beds) {
167-
this.beds = beds;
168-
}
169-
170-
@NotEmpty
171-
public String getCreditCardName() {
172-
return creditCardName;
173-
}
174-
175-
public void setCreditCardName(String creditCardName) {
176-
this.creditCardName = creditCardName;
177-
}
178-
179-
public int getCreditCardExpiryMonth() {
180-
return creditCardExpiryMonth;
181-
}
182-
183-
public void setCreditCardExpiryMonth(int creditCardExpiryMonth) {
184-
this.creditCardExpiryMonth = creditCardExpiryMonth;
185-
}
186-
187-
public int getCreditCardExpiryYear() {
188-
return creditCardExpiryYear;
189-
}
190-
191-
public void setCreditCardExpiryYear(int creditCardExpiryYear) {
192-
this.creditCardExpiryYear = creditCardExpiryYear;
193-
}
194-
195-
@Transient
196-
public Amenity[] getAmenities() {
197-
return amenities;
198-
}
199-
200-
public void setAmenities(Amenity[] amenities) {
201-
this.amenities = amenities;
202-
}
203-
204-
public void validateEnterBookingDetails(ValidationContext context) {
205-
MessageContext messages = context.getMessageContext();
206-
if (checkinDate.before(today())) {
207-
messages.addMessage(new MessageBuilder().error().source("checkinDate")
208-
.code("booking.checkinDate.beforeToday").build());
209-
} else if (checkoutDate.before(checkinDate)) {
210-
messages.addMessage(new MessageBuilder().error().source("checkoutDate")
211-
.code("booking.checkoutDate.beforeCheckinDate").build());
212-
}
213-
}
214-
215-
private Date today() {
216-
Calendar calendar = Calendar.getInstance();
217-
calendar.add(Calendar.DAY_OF_MONTH, -1);
218-
return calendar.getTime();
219-
}
220-
221-
@Override
222-
public String toString() {
223-
return "Booking(" + user + "," + hotel + ")";
224-
}
187+
public int getCreditCardExpiryYear() {
188+
return creditCardExpiryYear;
189+
}
190+
191+
public void setCreditCardExpiryYear(int creditCardExpiryYear) {
192+
this.creditCardExpiryYear = creditCardExpiryYear;
193+
}
194+
195+
@Transient
196+
public Amenity[] getAmenities() {
197+
return amenities;
198+
}
199+
200+
public void setAmenities(Amenity[] amenities) {
201+
this.amenities = amenities;
202+
}
203+
204+
public void validateEnterBookingDetails(ValidationContext context) {
205+
MessageContext messages = context.getMessageContext();
206+
if (checkinDate.before(today())) {
207+
messages.addMessage(new MessageBuilder().error().source("checkinDate")
208+
.code("booking.checkinDate.beforeToday").build());
209+
} else if (checkoutDate.before(checkinDate)) {
210+
messages.addMessage(new MessageBuilder().error().source("checkoutDate")
211+
.code("booking.checkoutDate.beforeCheckinDate").build());
212+
}
213+
}
214+
215+
private Date today() {
216+
Calendar calendar = Calendar.getInstance();
217+
calendar.add(Calendar.DAY_OF_MONTH, -1);
218+
return calendar.getTime();
219+
}
220+
221+
@Override
222+
public String toString() {
223+
return "Booking(" + user + "," + hotel + ")";
224+
}
225225

226226
}

0 commit comments

Comments
 (0)