Merge remote-tracking branch 'origin/development'
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / dataschema / Reservation.java
CommitLineData
9a78ca13
MT
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
81c3aac6
MT
10import java.util.UUID;\r
11\r
9a78ca13
MT
12import ch.bfh.ti.daterange.DateRange;\r
13\r
d103d4ec 14public class Reservation implements Modifiable {\r
9a78ca13 15\r
81c3aac6
MT
16 private UUID id;\r
17 private UUID groupId;\r
9a78ca13
MT
18 private User user;\r
19 private Resource resource;\r
20 private DateRange dateRange;\r
81c3aac6
MT
21 private String remark;\r
22\r
d103d4ec
MT
23 /**\r
24 * Normal constructor for new reservation created in the Controller\r
73469283
D
25 * @param groupId\r
26 * id of reservation group when reocuring reservation, 0 when\r
27 * single reservation\r
d103d4ec 28 * @param user\r
73469283 29 * user who created the reservation\r
d103d4ec 30 * @param resource\r
73469283 31 * reserved resource\r
d103d4ec 32 * @param dateRange\r
73469283 33 * daterange of the reservation\r
d103d4ec 34 * @param remark\r
73469283 35 * remark\r
d103d4ec
MT
36 * @throws IllegalArgumentException\r
37 * the name of the user and resource can't be null\r
38 */\r
73469283 39\r
d103d4ec 40 public Reservation(UUID groupId, User user, Resource resource, DateRange dateRange, String remark) {\r
912c75db
MT
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
9a78ca13 45\r
a49c468f 46 this.groupId = groupId;\r
9a78ca13
MT
47 this.user = user;\r
48 this.resource = resource;\r
d103d4ec 49 this.dateRange = dateRange;\r
81c3aac6 50 this.remark = remark;\r
66cc653d 51\r
a49c468f 52 this.id = UUID.randomUUID();\r
9a78ca13
MT
53 }\r
54\r
a49c468f
MT
55 public UUID getId() {\r
56 return id;\r
57 }\r
66cc653d 58\r
a49c468f
MT
59 public UUID getGroupId() {\r
60 return groupId;\r
61 }\r
66cc653d 62\r
9a78ca13
MT
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
81c3aac6
MT
75 public String getRemark() {\r
76 return remark;\r
9a78ca13 77 }\r
66cc653d 78\r
9a78ca13
MT
79 public void setUser(User user) {\r
80 this.user = user;\r
81 }\r
66cc653d 82\r
9a78ca13
MT
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
81c3aac6
MT
90\r
91 public void setRemark(String remark) {\r
92 this.remark = remark;\r
93 }\r
66cc653d 94\r
5fca88b4
MT
95 @Override\r
96 public boolean isModified(Object obj) {\r
97 if (obj == this) {\r
912c75db
MT
98 return false;\r
99 }\r
5fca88b4 100 if (obj == null) {\r
912c75db
MT
101 return true;\r
102 }\r
5fca88b4 103 Reservation otherReservation = (Reservation) obj;\r
912c75db
MT
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
a08b0437
M
109 @Override\r
110 public Reservation clone() throws CloneNotSupportedException {\r
66cc653d
D
111 return (Reservation) super.clone();\r
112 }\r
9a78ca13 113}\r