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