src/share/classes/java/util/GregorianCalendar.java

Print this page

        

*** 39,53 **** package java.util; import java.io.IOException; import java.io.ObjectInputStream; import java.time.Instant; - import java.time.ZoneId; import java.time.ZonedDateTime; - import java.time.chrono.IsoChronology; import java.time.temporal.ChronoField; - import java.time.temporal.TemporalQuery; import sun.util.calendar.BaseCalendar; import sun.util.calendar.CalendarDate; import sun.util.calendar.CalendarSystem; import sun.util.calendar.CalendarUtils; import sun.util.calendar.Era; --- 39,50 ----
*** 865,883 **** --- 862,882 ---- * @param obj the object to compare with. * @return <code>true</code> if this object is equal to <code>obj</code>; * <code>false</code> otherwise. * @see Calendar#compareTo(Calendar) */ + @Override public boolean equals(Object obj) { return obj instanceof GregorianCalendar && super.equals(obj) && gregorianCutover == ((GregorianCalendar)obj).gregorianCutover; } /** * Generates the hash code for this <code>GregorianCalendar</code> object. */ + @Override public int hashCode() { return super.hashCode() ^ (int)gregorianCutoverDate; } /**
*** 906,915 **** --- 905,915 ---- * @exception IllegalArgumentException if <code>field</code> is * <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or unknown, * or if any calendar fields have out-of-range values in * non-lenient mode. */ + @Override public void add(int field, int amount) { // If amount == 0, do nothing even the given field is out of // range. This is tested by JCK. if (amount == 0) { return; // Do nothing!
*** 1104,1113 **** --- 1104,1114 ---- * or if any calendar fields have out-of-range values in * non-lenient mode. * @see #add(int,int) * @see #set(int,int) */ + @Override public void roll(int field, boolean up) { roll(field, up ? +1 : -1); } /**
*** 1152,1161 **** --- 1153,1163 ---- * @see #roll(int,boolean) * @see #add(int,int) * @see #set(int,int) * @since 1.2 */ + @Override public void roll(int field, int amount) { // If amount == 0, do nothing even the given field is out of // range. This is tested by JCK. if (amount == 0) { return;
*** 1270,1298 **** max = getActualMaximum(WEEK_OF_YEAR); set(DAY_OF_WEEK, internalGet(DAY_OF_WEEK)); int woy = internalGet(WEEK_OF_YEAR); int value = woy + amount; if (!isCutoverYear(y)) { // If the new value is in between min and max // (exclusive), then we can use the value. if (value > min && value < max) { set(WEEK_OF_YEAR, value); return; } long fd = getCurrentFixedDate(); // Make sure that the min week has the current DAY_OF_WEEK long day1 = fd - (7 * (woy - min)); if (calsys.getYearFromFixedDate(day1) != y) { min++; } // Make sure the same thing for the max week fd += 7 * (max - internalGet(WEEK_OF_YEAR)); if (calsys.getYearFromFixedDate(fd) != y) { max--; } ! break; } // Handle cutover here. long fd = getCurrentFixedDate(); BaseCalendar cal; --- 1272,1319 ---- max = getActualMaximum(WEEK_OF_YEAR); set(DAY_OF_WEEK, internalGet(DAY_OF_WEEK)); int woy = internalGet(WEEK_OF_YEAR); int value = woy + amount; if (!isCutoverYear(y)) { + int weekYear = getWeekYear(); + if (weekYear == y) { // If the new value is in between min and max // (exclusive), then we can use the value. if (value > min && value < max) { set(WEEK_OF_YEAR, value); return; } long fd = getCurrentFixedDate(); // Make sure that the min week has the current DAY_OF_WEEK + // in the calendar year long day1 = fd - (7 * (woy - min)); if (calsys.getYearFromFixedDate(day1) != y) { min++; } // Make sure the same thing for the max week fd += 7 * (max - internalGet(WEEK_OF_YEAR)); if (calsys.getYearFromFixedDate(fd) != y) { max--; } ! } else { ! // When WEEK_OF_YEAR and YEAR are out of sync, ! // adjust woy and amount to stay in the calendar year. ! if (weekYear > y) { ! if (amount < 0) { ! amount++; ! } ! woy = max; ! } else { ! if (amount > 0) { ! amount -= woy - max; ! } ! woy = min; ! } ! } ! set(field, getRolledValue(woy, amount, min, max)); ! return; } // Handle cutover here. long fd = getCurrentFixedDate(); BaseCalendar cal;
*** 1508,1517 **** --- 1529,1539 ---- * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) */ + @Override public int getMinimum(int field) { return MIN_VALUES[field]; } /**
*** 1531,1540 **** --- 1553,1563 ---- * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) */ + @Override public int getMaximum(int field) { switch (field) { case MONTH: case DAY_OF_MONTH: case DAY_OF_YEAR:
*** 1579,1588 **** --- 1602,1612 ---- * @see #getMaximum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) */ + @Override public int getGreatestMinimum(int field) { if (field == DAY_OF_MONTH) { BaseCalendar.Date d = getGregorianCutoverDate(); long mon1 = getFixedDateMonth1(d, gregorianCutoverDate); d = getCalendarDate(mon1);
*** 1608,1617 **** --- 1632,1642 ---- * @see #getMaximum(int) * @see #getGreatestMinimum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) */ + @Override public int getLeastMaximum(int field) { switch (field) { case MONTH: case DAY_OF_MONTH: case DAY_OF_YEAR:
*** 1657,1666 **** --- 1682,1692 ---- * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMaximum(int) * @since 1.2 */ + @Override public int getActualMinimum(int field) { if (field == DAY_OF_MONTH) { GregorianCalendar gc = getNormalizedCalendar(); int year = gc.cdate.getNormalizedYear(); if (year == gregorianCutoverYear || year == gregorianCutoverYearJulian) {
*** 1700,1709 **** --- 1726,1736 ---- * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @since 1.2 */ + @Override public int getActualMaximum(int field) { final int fieldsForFixedMax = ERA_MASK|DAY_OF_WEEK_MASK|HOUR_MASK|AM_PM_MASK| HOUR_OF_DAY_MASK|MINUTE_MASK|SECOND_MASK|MILLISECOND_MASK| ZONE_OFFSET_MASK|DST_OFFSET_MASK; if ((fieldsForFixedMax & (1<<field)) != 0) {
*** 1968,1977 **** --- 1995,2005 ---- t *= 1000; return t + internalGet(MILLISECOND) - (internalGet(ZONE_OFFSET) + internalGet(DST_OFFSET)); } + @Override public Object clone() { GregorianCalendar other = (GregorianCalendar) super.clone(); other.gdate = (BaseCalendar.Date) gdate.clone();
*** 1985,2004 **** --- 2013,2034 ---- other.originalFields = null; other.zoneOffsets = null; return other; } + @Override public TimeZone getTimeZone() { TimeZone zone = super.getTimeZone(); // To share the zone by CalendarDates gdate.setZone(zone); if (cdate != null && cdate != gdate) { cdate.setZone(zone); } return zone; } + @Override public void setTimeZone(TimeZone zone) { super.setTimeZone(zone); // To share the zone by CalendarDates gdate.setZone(zone); if (cdate != null && cdate != gdate) {
*** 2225,2234 **** --- 2255,2265 ---- * @see Calendar#WEEK_OF_YEAR * @see #getWeekYear() * @see #getActualMaximum(int) * @since 1.7 */ + @Override public int getWeeksInWeekYear() { GregorianCalendar gc = getNormalizedCalendar(); int weekYear = gc.getWeekYear(); if (weekYear == gc.internalGet(YEAR)) { return gc.getActualMaximum(WEEK_OF_YEAR);
*** 2260,2271 **** * recomputed first; to recompute the time, then the fields, call the * <code>complete</code> method. * * @see Calendar#complete */ protected void computeFields() { ! int mask = 0; if (isPartiallyNormalized()) { // Determine which calendar fields need to be computed. mask = getSetStateFields(); int fieldMask = ~mask & ALL_FIELDS; // We have to call computTime in case calsys == null in --- 2291,2303 ---- * recomputed first; to recompute the time, then the fields, call the * <code>complete</code> method. * * @see Calendar#complete */ + @Override protected void computeFields() { ! int mask; if (isPartiallyNormalized()) { // Determine which calendar fields need to be computed. mask = getSetStateFields(); int fieldMask = ~mask & ALL_FIELDS; // We have to call computTime in case calsys == null in
*** 2596,2605 **** --- 2628,2638 ---- * Converts calendar field values to the time value (millisecond * offset from the <a href="Calendar.html#Epoch">Epoch</a>). * * @exception IllegalArgumentException if any calendar fields are invalid. */ + @Override protected void computeTime() { // In non-lenient mode, perform brief checking of calendar // fields which have been set externally. Through this // checking, the field values are stored in originalFields[] // to see if any of them are normalized later.