1 /*
2 * Licensed to The Apereo Foundation under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional
4 * information regarding copyright ownership.
5 *
6 *
7 * The Apereo Foundation licenses this file to you under the Educational
8 * Community License, Version 2.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of the License
10 * at:
11 *
12 * http://opensource.org/licenses/ecl2.txt
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 *
20 */
21 package org.opencastproject.scheduler.api;
22
23 import static org.opencastproject.util.EqualsUtil.eq;
24
25 import org.opencastproject.util.EqualsUtil;
26 import org.opencastproject.util.data.Option;
27
28 import java.util.Date;
29
30 import javax.annotation.concurrent.ThreadSafe;
31
32 /** Business object for a period. */
33 @ThreadSafe
34 public final class Period {
35 /** The period identifier */
36 private final Option<Long> id;
37
38 /** The start date */
39 private final Date start;
40
41 /** The end date */
42 private final Date end;
43
44 /** The purpose */
45 private final Option<String> purpose;
46
47 /** The comment */
48 private final Option<String> comment;
49
50 /**
51 * Creates a period
52 *
53 * @param id
54 * the id
55 * @param start
56 * the start date
57 * @param end
58 * the end date
59 * @param purpose
60 * the purpose
61 * @param comment
62 * the comment
63 */
64 public Period(Option<Long> id, Date start, Date end, Option<String> purpose, Option<String> comment) {
65 this.id = id;
66 this.start = start;
67 this.end = end;
68 this.purpose = purpose;
69 this.comment = comment;
70 }
71
72 /**
73 * Returns the period id
74 *
75 * @return the id
76 */
77 public Option<Long> getId() {
78 return this.id;
79 }
80
81 /**
82 * Returns the start date
83 *
84 * @return the start date
85 */
86 public Date getStart() {
87 return start;
88 }
89
90 /**
91 * Returns the end date
92 *
93 * @return the end date
94 */
95 public Date getEnd() {
96 return end;
97 }
98
99 /**
100 * Returns the purpose
101 *
102 * @return the purpose
103 */
104 public Option<String> getPurpose() {
105 return purpose;
106 }
107
108 /**
109 * Returns the comment
110 *
111 * @return the comment
112 */
113 public Option<String> getComment() {
114 return comment;
115 }
116
117 @Override
118 public boolean equals(Object that) {
119 return (this == that) || (that instanceof Period && eqFields((Period) that));
120 }
121
122 private boolean eqFields(Period that) {
123 return eq(this.id, that.id) && eq(this.start, that.start) && eq(this.end, that.end)
124 && eq(this.purpose, that.purpose) && eq(this.comment, that.comment);
125 }
126
127 @Override
128 public int hashCode() {
129 return EqualsUtil.hash(id, start, end, purpose, comment);
130 }
131
132 }