| DayAndPosition.java |
1 /*
2 * Copyright (c) 2000, Columbia University. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
19 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 package com.liferay.util.cal;
32
33 import com.liferay.portal.kernel.util.StringMaker;
34
35 import java.io.Serializable;
36
37 import java.util.Calendar;
38
39 /**
40 * <a href="DayAndPosition.java.html"><b><i>View Source</i></b></a>
41 *
42 * @author Jonathan Lennox
43 *
44 * @deprecated This class has been repackaged at
45 * <code>com.liferay.portal.kernel.cal</code>.
46 *
47 */
48 public class DayAndPosition implements Cloneable, Serializable {
49
50 /**
51 * Field day
52 */
53 private int day;
54
55 /**
56 * Field position
57 */
58 private int position;
59
60 /**
61 * Field NO_WEEKDAY
62 */
63 public final static int NO_WEEKDAY = 0;
64
65 /**
66 * Constructor DayAndPosition
67 *
68 *
69 */
70 public DayAndPosition() {
71 day = NO_WEEKDAY;
72 position = 0;
73 }
74
75 /**
76 * Constructor DayAndPosition
77 *
78 *
79 * @param d
80 * @param p
81 *
82 */
83 public DayAndPosition(int d, int p) {
84 if (!isValidDayOfWeek(d)) {
85 throw new IllegalArgumentException("Invalid day of week");
86 }
87
88 if (!isValidDayPosition(p)) {
89 throw new IllegalArgumentException("Invalid day position");
90 }
91
92 day = d;
93 position = p;
94 }
95
96 /**
97 * Method getDayOfWeek
98 *
99 *
100 * @return int
101 *
102 */
103 public int getDayOfWeek() {
104 return day;
105 }
106
107 /**
108 * Method setDayOfWeek
109 *
110 *
111 * @param d
112 *
113 */
114 public void setDayOfWeek(int d) {
115 if (!isValidDayOfWeek(d)) {
116 throw new IllegalArgumentException("Invalid day of week");
117 }
118
119 day = d;
120 }
121
122 /**
123 * Method getDayPosition
124 *
125 *
126 * @return int
127 *
128 */
129 public int getDayPosition() {
130 return position;
131 }
132
133 /**
134 * Method setDayPosition
135 *
136 *
137 * @param p
138 *
139 */
140 public void setDayPosition(int p) {
141 if (!isValidDayPosition(p)) {
142 throw new IllegalArgumentException();
143 }
144
145 position = p;
146 }
147
148 /**
149 * Method equals
150 *
151 *
152 * @param obj
153 *
154 * @return boolean
155 *
156 */
157 public boolean equals(Object obj) {
158 if (obj == null) {
159 return false;
160 }
161
162 if (this == obj) {
163 return true;
164 }
165
166 if (!(obj instanceof DayAndPosition)) {
167 return false;
168 }
169
170 DayAndPosition that = (DayAndPosition)obj;
171
172 return (getDayOfWeek() == that.getDayOfWeek())
173 && (getDayPosition() == that.getDayPosition());
174 }
175
176 /**
177 * Method isValidDayOfWeek
178 *
179 *
180 * @param d
181 *
182 * @return boolean
183 *
184 */
185 public static boolean isValidDayOfWeek(int d) {
186 switch (d) {
187
188 case NO_WEEKDAY :
189 case Calendar.SUNDAY :
190 case Calendar.MONDAY :
191 case Calendar.TUESDAY :
192 case Calendar.WEDNESDAY :
193 case Calendar.THURSDAY :
194 case Calendar.FRIDAY :
195 case Calendar.SATURDAY :
196 return true;
197
198 default :
199 return false;
200 }
201 }
202
203 /**
204 * Method isValidDayPosition
205 *
206 *
207 * @param p
208 *
209 * @return boolean
210 *
211 */
212 public static boolean isValidDayPosition(int p) {
213 return ((p >= -53) && (p <= 53));
214 }
215
216 /**
217 * Method clone
218 *
219 *
220 * @return Object
221 *
222 */
223 public Object clone() {
224 try {
225 DayAndPosition other = (DayAndPosition)super.clone();
226
227 other.day = day;
228 other.position = position;
229
230 return other;
231 }
232 catch (CloneNotSupportedException e) {
233 throw new InternalError();
234 }
235 }
236
237 /**
238 * Method toString
239 *
240 *
241 * @return String
242 *
243 */
244 public String toString() {
245 StringMaker sm = new StringMaker();
246
247 sm.append(getClass().getName());
248 sm.append("[day=");
249 sm.append(day);
250 sm.append(",position=");
251 sm.append(position);
252 sm.append("]");
253
254 return sm.toString();
255 }
256
257 }