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