1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.custom.schedule.model;
21
22 import java.io.Serializable;
23 import java.util.Calendar;
24 import java.util.Date;
25 import java.util.TimeZone;
26
27 import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
28
29
30
31
32
33
34
35
36
37
38 public class Interval implements Serializable, Comparable
39 {
40
41 private String label;
42 private Date startTime;
43 private Date endTime;
44
45 public Interval(String label, Date startTime, Date endTime)
46 {
47 this.label = label;
48 this.startTime = startTime;
49 this.endTime = endTime;
50 }
51
52 public String getLabel()
53 {
54 return label;
55 }
56 public void setLabel(String label)
57 {
58 this.label = label;
59 }
60
61 public Date getStartTime()
62 {
63 return startTime;
64 }
65 public void setStartTime(Date startTime)
66 {
67 this.startTime = startTime;
68 }
69
70 public Date getEndTime()
71 {
72 return endTime;
73 }
74 public void setEndTime(Date endTime)
75 {
76 this.endTime = endTime;
77 }
78
79 public boolean containsDate(Date clickedDate)
80 {
81 return !getStartTime().after(clickedDate) && clickedDate.before(getEndTime());
82 }
83
84 public int compareTo(Object o)
85 {
86 if (o instanceof Interval)
87 {
88
89 return startTime.compareTo(((Interval) o).startTime);
90 }
91
92 return 1;
93 }
94
95 public boolean after(Interval last)
96 {
97
98 return !startTime.before(last.getEndTime());
99 }
100
101 public int getStartHours(TimeZone timeZone)
102 {
103
104 return ScheduleUtil.getCalendarInstance(getStartTime(), timeZone).get(Calendar.HOUR_OF_DAY);
105 }
106
107 public int getStartMinutes(TimeZone timeZone)
108 {
109
110 return ScheduleUtil.getCalendarInstance(getStartTime(), timeZone).get(Calendar.MINUTE);
111 }
112
113 public long getDuration()
114 {
115
116 return getEndTime().getTime() - getStartTime().getTime();
117 }
118
119
120
121
122
123
124
125
126
127
128
129 public boolean isEquivalent(Interval other)
130 {
131
132 return label.equals(other.label)
133 && ScheduleUtil.isSameTime(startTime, other.startTime)
134 && ScheduleUtil.isSameTime(endTime, other.endTime);
135 }
136
137 public int hashCode() {
138
139 return label.hashCode() + startTime.hashCode() + endTime.hashCode();
140 }
141
142 public boolean equals(Object obj)
143 {
144 if (obj != null && obj instanceof Interval) {
145 Interval other = (Interval) obj;
146
147 return label.equals(other.label)
148 && startTime.equals(other.startTime)
149 && endTime.equals(other.endTime);
150 }
151
152 return false;
153 }
154
155 public String toString()
156 {
157
158 return this.getClass().getName() + " Start:" + startTime + " End:" + endTime;
159 }
160 }