/ftr-gwt-date-emulation/src/test/java/eu/future/earth/gwt/emul/java/util/Calendar.java
Java | 416 lines | 66 code | 55 blank | 295 comment | 0 complexity | 574946f5548a88a790829512f51d8c9d MD5 | raw file
Possible License(s): Apache-2.0
1/** 2 * This class gets copy-and-pasted between the eu.future.earth.gwt.emul.java.util (used for 3 * development and testing) and com.google.gwt.emul.java.util packages (used for gwt 4 * compilation). Change the comments on the package declaration appropriately. 5 */ 6package eu.future.earth.gwt.emul.java.util; 7//package java.util; 8 9import java.util.Date; 10 11public abstract class Calendar implements Cloneable { 12 13 protected Calendar(){ 14 super(); 15 } 16 17 /** 18 * Field number for <code>get</code> and <code>set</code> indicating the 19 * year. This is a calendar-specific value; see subclass documentation. 20 */ 21 public final static int YEAR = 1; 22 23 /** 24 * Field number for <code>get</code> and <code>set</code> indicating the 25 * month. This is a calendar-specific value. The first month of 26 * the year in the Gregorian and Julian calendars is 27 * <code>JANUARY</code> which is 0; the last depends on the number 28 * of months in a year. 29 * 30 * @see #JANUARY 31 * @see #FEBRUARY 32 * @see #MARCH 33 * @see #APRIL 34 * @see #MAY 35 * @see #JUNE 36 * @see #JULY 37 * @see #AUGUST 38 * @see #SEPTEMBER 39 * @see #OCTOBER 40 * @see #NOVEMBER 41 * @see #DECEMBER 42 * @see #UNDECIMBER 43 */ 44 public final static int MONTH = 2; 45 46 /** 47 * Field number for <code>get</code> and <code>set</code> indicating the 48 * week number within the current year. The first week of the year, as 49 * defined by <code>getFirstDayOfWeek()</code> and 50 * <code>getMinimalDaysInFirstWeek()</code>, has value 1. Subclasses define 51 * the value of <code>WEEK_OF_YEAR</code> for days before the first week of 52 * the year. 53 * 54 * @see #getFirstDayOfWeek 55 * @see #getMinimalDaysInFirstWeek 56 */ 57 public final static int WEEK_OF_YEAR = 3; 58 59 /** 60 * Field number for <code>get</code> and <code>set</code> indicating the 61 * week number within the current month. The first week of the month, as 62 * defined by <code>getFirstDayOfWeek()</code> and 63 * <code>getMinimalDaysInFirstWeek()</code>, has value 1. Subclasses define 64 * the value of <code>WEEK_OF_MONTH</code> for days before the first week of 65 * the month. 66 * 67 * @see #getFirstDayOfWeek 68 * @see #getMinimalDaysInFirstWeek 69 */ 70 public final static int WEEK_OF_MONTH = 4; 71 72 /** 73 * Field number for <code>get</code> and <code>set</code> indicating the 74 * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>. 75 * The first day of the month has value 1. 76 * 77 * @see #DAY_OF_MONTH 78 */ 79 public final static int DATE = 5; 80 81 /** 82 * Field number for <code>get</code> and <code>set</code> indicating the 83 * day of the month. This is a synonym for <code>DATE</code>. 84 * The first day of the month has value 1. 85 * 86 * @see #DATE 87 */ 88 public final static int DAY_OF_MONTH = 5; 89 90 /** 91 * Field number for <code>get</code> and <code>set</code> indicating the day 92 * number within the current year. The first day of the year has value 1. 93 */ 94 public final static int DAY_OF_YEAR = 6; 95 96 /** 97 * Field number for <code>get</code> and <code>set</code> indicating the day 98 * of the week. This field takes values <code>SUNDAY</code>, 99 * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>, 100 * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>. 101 * 102 * @see #SUNDAY 103 * @see #MONDAY 104 * @see #TUESDAY 105 * @see #WEDNESDAY 106 * @see #THURSDAY 107 * @see #FRIDAY 108 * @see #SATURDAY 109 */ 110 public final static int DAY_OF_WEEK = 7; 111 112 /** 113 * Field number for <code>get</code> and <code>set</code> indicating the 114 * ordinal number of the day of the week within the current month. Together 115 * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day 116 * within a month. Unlike <code>WEEK_OF_MONTH</code> and 117 * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on 118 * <code>getFirstDayOfWeek()</code> or 119 * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code> 120 * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH 121 * 1</code>; <code>8</code> through <code>14</code> correspond to 122 * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on. 123 * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before 124 * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the 125 * end of the month, so the last Sunday of a month is specified as 126 * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because 127 * negative values count backward they will usually be aligned differently 128 * within the month than positive values. For example, if a month has 31 129 * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap 130 * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>. 131 * 132 * @see #DAY_OF_WEEK 133 * @see #WEEK_OF_MONTH 134 */ 135 public final static int DAY_OF_WEEK_IN_MONTH = 8; 136 137 /** 138 * Field number for <code>get</code> and <code>set</code> indicating 139 * whether the <code>HOUR</code> is before or after noon. 140 * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>. 141 * 142 * @see #AM 143 * @see #PM 144 * @see #HOUR 145 */ 146 public final static int AM_PM = 9; 147 148 /** 149 * Field number for <code>get</code> and <code>set</code> indicating the 150 * hour of the morning or afternoon. <code>HOUR</code> is used for the 151 * 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12. 152 * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10. 153 * 154 * @see #AM_PM 155 * @see #HOUR_OF_DAY 156 */ 157 public final static int HOUR = 10; 158 159 /** 160 * Field number for <code>get</code> and <code>set</code> indicating the 161 * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock. 162 * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22. 163 * 164 * @see #HOUR 165 */ 166 public final static int HOUR_OF_DAY = 11; 167 168 /** 169 * Field number for <code>get</code> and <code>set</code> indicating the 170 * minute within the hour. 171 * E.g., at 10:04:15.250 PM the <code>MINUTE</code> is 4. 172 */ 173 public final static int MINUTE = 12; 174 175 /** 176 * Field number for <code>get</code> and <code>set</code> indicating the 177 * second within the minute. 178 * E.g., at 10:04:15.250 PM the <code>SECOND</code> is 15. 179 */ 180 public final static int SECOND = 13; 181 182 /** 183 * Field number for <code>get</code> and <code>set</code> indicating the 184 * millisecond within the second. 185 * E.g., at 10:04:15.250 PM the <code>MILLISECOND</code> is 250. 186 */ 187 public final static int MILLISECOND = 14; 188 189 /** 190 * Value of the {@link #DAY_OF_WEEK} field indicating 191 * Sunday. 192 */ 193 public final static int SUNDAY = 1; 194 195 /** 196 * Value of the {@link #DAY_OF_WEEK} field indicating 197 * Monday. 198 */ 199 public final static int MONDAY = 2; 200 201 /** 202 * Value of the {@link #DAY_OF_WEEK} field indicating 203 * Tuesday. 204 */ 205 public final static int TUESDAY = 3; 206 207 /** 208 * Value of the {@link #DAY_OF_WEEK} field indicating 209 * Wednesday. 210 */ 211 public final static int WEDNESDAY = 4; 212 213 /** 214 * Value of the {@link #DAY_OF_WEEK} field indicating 215 * Thursday. 216 */ 217 public final static int THURSDAY = 5; 218 219 /** 220 * Value of the {@link #DAY_OF_WEEK} field indicating 221 * Friday. 222 */ 223 public final static int FRIDAY = 6; 224 225 /** 226 * Value of the {@link #DAY_OF_WEEK} field indicating 227 * Saturday. 228 */ 229 public final static int SATURDAY = 7; 230 231 /** 232 * Value of the {@link #MONTH} field indicating the 233 * first month of the year in the Gregorian and Julian calendars. 234 */ 235 public final static int JANUARY = 0; 236 237 /** 238 * Value of the {@link #MONTH} field indicating the 239 * second month of the year in the Gregorian and Julian calendars. 240 */ 241 public final static int FEBRUARY = 1; 242 243 /** 244 * Value of the {@link #MONTH} field indicating the 245 * third month of the year in the Gregorian and Julian calendars. 246 */ 247 public final static int MARCH = 2; 248 249 /** 250 * Value of the {@link #MONTH} field indicating the 251 * fourth month of the year in the Gregorian and Julian calendars. 252 */ 253 public final static int APRIL = 3; 254 255 /** 256 * Value of the {@link #MONTH} field indicating the 257 * fifth month of the year in the Gregorian and Julian calendars. 258 */ 259 public final static int MAY = 4; 260 261 /** 262 * Value of the {@link #MONTH} field indicating the 263 * sixth month of the year in the Gregorian and Julian calendars. 264 */ 265 public final static int JUNE = 5; 266 267 /** 268 * Value of the {@link #MONTH} field indicating the 269 * seventh month of the year in the Gregorian and Julian calendars. 270 */ 271 public final static int JULY = 6; 272 273 /** 274 * Value of the {@link #MONTH} field indicating the 275 * eighth month of the year in the Gregorian and Julian calendars. 276 */ 277 public final static int AUGUST = 7; 278 279 /** 280 * Value of the {@link #MONTH} field indicating the 281 * ninth month of the year in the Gregorian and Julian calendars. 282 */ 283 public final static int SEPTEMBER = 8; 284 285 /** 286 * Value of the {@link #MONTH} field indicating the 287 * tenth month of the year in the Gregorian and Julian calendars. 288 */ 289 public final static int OCTOBER = 9; 290 291 /** 292 * Value of the {@link #MONTH} field indicating the 293 * eleventh month of the year in the Gregorian and Julian calendars. 294 */ 295 public final static int NOVEMBER = 10; 296 297 /** 298 * Value of the {@link #MONTH} field indicating the 299 * twelfth month of the year in the Gregorian and Julian calendars. 300 */ 301 public final static int DECEMBER = 11; 302 303 /** 304 * Value of the {@link #MONTH} field indicating the 305 * thirteenth month of the year. Although <code>GregorianCalendar</code> 306 * does not use this value, lunar calendars do. 307 */ 308 public final static int UNDECIMBER = 12; 309 310 /** 311 * Value of the {@link #AM_PM} field indicating the 312 * period of the day from midnight to just before noon. 313 */ 314 public final static int AM = 0; 315 316 /** 317 * Value of the {@link #AM_PM} field indicating the 318 * period of the day from noon to just before midnight. 319 */ 320 public final static int PM = 1; 321 322 /** 323 * Returns a <code>Date</code> object representing this 324 * <code>Calendar</code>'s time value (millisecond offset from the <a 325 * href="#Epoch">Epoch</a>"). 326 * 327 * @return a <code>Date</code> representing the time value. 328 * @see #setTime(Date) 329 * @see #getTimeInMillis() 330 */ 331 public abstract Date getTime(); 332 333 /** 334 * Sets this Calendar's time with the given <code>Date</code>. 335 * <p> 336 * Note: Calling <code>setTime()</code> with 337 * <code>Date(Long.MAX_VALUE)</code> or <code>Date(Long.MIN_VALUE)</code> 338 * may yield incorrect field values from <code>get()</code>. 339 * 340 * @param date the given Date. 341 * @see #getTime() 342 * @see #setTimeInMillis(long) 343 */ 344 public abstract void setTime(Date date); 345 346 /** 347 * Returns this Calendar's time value in milliseconds. 348 * 349 * @return the current time as UTC milliseconds from the epoch. 350 * @see #getTime() 351 * @see #setTimeInMillis(long) 352 */ 353 public abstract long getTimeInMillis(); 354 355 /** 356 * Sets this Calendar's current time from the given long value. 357 * 358 * @param millis the new time in UTC milliseconds from the epoch. 359 * @see #setTime(Date) 360 * @see #getTimeInMillis() 361 */ 362 public abstract void setTimeInMillis(long millis); 363 364 public abstract int get(int field); 365 366 /** 367 * Sets the given calendar field to the given value. The value is not 368 * interpreted by this method regardless of the leniency mode. 369 * 370 * @param field the given calendar field. 371 * @param value the value to be set for the given calendar field. 372 * @throws ArrayIndexOutOfBoundsException if the specified field is out of range 373 * (<code>field < 0 || field >= FIELD_COUNT</code>). 374 * in non-lenient mode. 375 * @see #set(int,int,int) 376 * @see #set(int,int,int,int,int) 377 * @see #set(int,int,int,int,int,int) 378 * @see #get(int) 379 */ 380 public abstract void set(int field, int value); 381 382 public abstract void add(int field, int value); 383 384 public int getFirstDayOfWeek() { 385 return firstDayOfWeek; 386 } 387 388 public void setFirstDayOfWeek(int newFirstDayOfWeek) { 389 this.firstDayOfWeek = newFirstDayOfWeek; 390 } 391 392 public int getMinimalDaysInFirstWeek() { 393 return minimalDaysInFirstWeek; 394 } 395 396 public void setMinimalDaysInFirstWeek(int newMinimalDaysInFirstWeek) { 397 this.minimalDaysInFirstWeek = newMinimalDaysInFirstWeek; 398 } 399 400 /** 401 * The first day of the week, with possible values <code>SUNDAY</code>, 402 * <code>MONDAY</code>, etc. This is a locale-dependent value. 403 * @serial 404 */ 405 private int firstDayOfWeek = SUNDAY; 406 407 /** 408 * The number of days required for the first week in a month or year, 409 * with possible values from 1 to 7. This is a locale-dependent value. 410 * @serial 411 */ 412 private int minimalDaysInFirstWeek = 1; 413 414 public abstract Object clone(); 415 416}