Merge remote-tracking branch 'origin/development'
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / dataschema / Reservation.java
... / ...
CommitLineData
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
8package ch.bfh.ti.srs.dataschema;\r
9\r
10import java.util.UUID;\r
11\r
12import ch.bfh.ti.daterange.DateRange;\r
13\r
14public class Reservation implements Modifiable {\r
15\r
16 private UUID id;\r
17 private UUID groupId;\r
18 private User user;\r
19 private Resource resource;\r
20 private DateRange dateRange;\r
21 private String remark;\r
22\r
23 /**\r
24 * Normal constructor for new reservation created in the Controller\r
25 * @param groupId\r
26 * id of reservation group when reocuring reservation, 0 when\r
27 * single reservation\r
28 * @param user\r
29 * user who created the reservation\r
30 * @param resource\r
31 * reserved resource\r
32 * @param dateRange\r
33 * daterange of the reservation\r
34 * @param remark\r
35 * remark\r
36 * @throws IllegalArgumentException\r
37 * the name of the user and resource can't be null\r
38 */\r
39\r
40 public Reservation(UUID groupId, User user, Resource resource, DateRange dateRange, String remark) {\r
41 if (user == null)\r
42 throw new IllegalArgumentException("User must not be null");\r
43 if (resource == null)\r
44 throw new IllegalArgumentException("Resource must not be null");\r
45\r
46 this.groupId = groupId;\r
47 this.user = user;\r
48 this.resource = resource;\r
49 this.dateRange = dateRange;\r
50 this.remark = remark;\r
51\r
52 this.id = UUID.randomUUID();\r
53 }\r
54\r
55 public UUID getId() {\r
56 return id;\r
57 }\r
58\r
59 public UUID getGroupId() {\r
60 return groupId;\r
61 }\r
62\r
63 public User getUser() {\r
64 return user;\r
65 }\r
66\r
67 public Resource getResource() {\r
68 return resource;\r
69 }\r
70\r
71 public DateRange getDateRange() {\r
72 return dateRange;\r
73 }\r
74\r
75 public String getRemark() {\r
76 return remark;\r
77 }\r
78\r
79 public void setUser(User user) {\r
80 this.user = user;\r
81 }\r
82\r
83 public void setResource(Resource resource) {\r
84 this.resource = resource;\r
85 }\r
86\r
87 public void setDateRange(DateRange dateRange) {\r
88 this.dateRange = dateRange;\r
89 }\r
90\r
91 public void setRemark(String remark) {\r
92 this.remark = remark;\r
93 }\r
94\r
95 @Override\r
96 public boolean isModified(Object obj) {\r
97 if (obj == this) {\r
98 return false;\r
99 }\r
100 if (obj == null) {\r
101 return true;\r
102 }\r
103 Reservation otherReservation = (Reservation) obj;\r
104 return this.user != otherReservation.getUser() || this.resource != otherReservation.getResource()\r
105 || this.dateRange.compareTo(otherReservation.getDateRange()) != 0\r
106 || this.remark != otherReservation.getRemark();\r
107 }\r
108\r
109 @Override\r
110 public Reservation clone() throws CloneNotSupportedException {\r
111 return (Reservation) super.clone();\r
112 }\r
113}\r