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