src/share/classes/java/util/JapaneseImperialCalendar.java

Print this page




1915             for (int field = 0; field < FIELD_COUNT; field++) {
1916                 if (!isExternallySet(field)) {
1917                     continue;
1918                 }
1919                 if (originalFields[field] != internalGet(field)) {
1920                     int wrongValue = internalGet(field);
1921                     // Restore the original field values
1922                     System.arraycopy(originalFields, 0, fields, 0, fields.length);
1923                     throw new IllegalArgumentException(getFieldName(field) + "=" + wrongValue
1924                                                        + ", expected " + originalFields[field]);
1925                 }
1926             }
1927         }
1928         setFieldsNormalized(mask);
1929     }
1930 
1931     /**
1932      * Computes the fixed date under either the Gregorian or the
1933      * Julian calendar, using the given year and the specified calendar fields.
1934      *
1935      * @param cal the CalendarSystem to be used for the date calculation
1936      * @param year the normalized year number, with 0 indicating the
1937      * year 1 BCE, -1 indicating 2 BCE, etc.
1938      * @param fieldMask the calendar fields to be used for the date calculation
1939      * @return the fixed date
1940      * @see Calendar#selectFields
1941      */
1942     private long getFixedDate(int era, int year, int fieldMask) {
1943         int month = JANUARY;
1944         int firstDayOfMonth = 1;
1945         if (isFieldSet(fieldMask, MONTH)) {
1946             // No need to check if MONTH has been set (no isSet(MONTH)
1947             // call) since its unset value happens to be JANUARY (0).
1948             month = internalGet(MONTH);
1949 
1950             // If the month is out of range, adjust it into range.
1951             if (month > DECEMBER) {
1952                 year += month / 12;
1953                 month %= 12;
1954             } else if (month < JANUARY) {
1955                 int[] rem = new int[1];


2124 
2125         // Otherwise, we can use the 1st day of the month.
2126         return fixedDate - date.getDayOfMonth() + 1;
2127     }
2128 
2129     /**
2130      * Returns a LocalGregorianCalendar.Date produced from the specified fixed date.
2131      *
2132      * @param fd the fixed date
2133      */
2134     private static LocalGregorianCalendar.Date getCalendarDate(long fd) {
2135         LocalGregorianCalendar.Date d = jcal.newCalendarDate(TimeZone.NO_TIMEZONE);
2136         jcal.getCalendarDateFromFixedDate(d, fd);
2137         return d;
2138     }
2139 
2140     /**
2141      * Returns the length of the specified month in the specified
2142      * Gregorian year. The year number must be normalized.
2143      *
2144      * @see #isLeapYear(int)
2145      */
2146     private int monthLength(int month, int gregorianYear) {
2147         return CalendarUtils.isGregorianLeapYear(gregorianYear) ?
2148             GregorianCalendar.LEAP_MONTH_LENGTH[month] : GregorianCalendar.MONTH_LENGTH[month];
2149     }
2150 
2151     /**
2152      * Returns the length of the specified month in the year provided
2153      * by internalGet(YEAR).
2154      *
2155      * @see #isLeapYear(int)
2156      */
2157     private int monthLength(int month) {
2158         assert jdate.isNormalized();
2159         return jdate.isLeapYear() ?
2160             GregorianCalendar.LEAP_MONTH_LENGTH[month] : GregorianCalendar.MONTH_LENGTH[month];
2161     }
2162 
2163     private int actualMonthLength() {
2164         int length = jcal.getMonthLength(jdate);
2165         int eraIndex = getTransitionEraIndex(jdate);
2166         if (eraIndex == -1) {
2167             long transitionFixedDate = sinceFixedDates[eraIndex];
2168             CalendarDate d = eras[eraIndex].getSinceDate();
2169             if (transitionFixedDate <= cachedFixedDate) {
2170                 length -= d.getDayOfMonth() - 1;
2171             } else {
2172                 length = d.getDayOfMonth() - 1;
2173             }
2174         }
2175         return length;




1915             for (int field = 0; field < FIELD_COUNT; field++) {
1916                 if (!isExternallySet(field)) {
1917                     continue;
1918                 }
1919                 if (originalFields[field] != internalGet(field)) {
1920                     int wrongValue = internalGet(field);
1921                     // Restore the original field values
1922                     System.arraycopy(originalFields, 0, fields, 0, fields.length);
1923                     throw new IllegalArgumentException(getFieldName(field) + "=" + wrongValue
1924                                                        + ", expected " + originalFields[field]);
1925                 }
1926             }
1927         }
1928         setFieldsNormalized(mask);
1929     }
1930 
1931     /**
1932      * Computes the fixed date under either the Gregorian or the
1933      * Julian calendar, using the given year and the specified calendar fields.
1934      *
1935      * @param era era index
1936      * @param year the normalized year number, with 0 indicating the
1937      * year 1 BCE, -1 indicating 2 BCE, etc.
1938      * @param fieldMask the calendar fields to be used for the date calculation
1939      * @return the fixed date
1940      * @see Calendar#selectFields
1941      */
1942     private long getFixedDate(int era, int year, int fieldMask) {
1943         int month = JANUARY;
1944         int firstDayOfMonth = 1;
1945         if (isFieldSet(fieldMask, MONTH)) {
1946             // No need to check if MONTH has been set (no isSet(MONTH)
1947             // call) since its unset value happens to be JANUARY (0).
1948             month = internalGet(MONTH);
1949 
1950             // If the month is out of range, adjust it into range.
1951             if (month > DECEMBER) {
1952                 year += month / 12;
1953                 month %= 12;
1954             } else if (month < JANUARY) {
1955                 int[] rem = new int[1];


2124 
2125         // Otherwise, we can use the 1st day of the month.
2126         return fixedDate - date.getDayOfMonth() + 1;
2127     }
2128 
2129     /**
2130      * Returns a LocalGregorianCalendar.Date produced from the specified fixed date.
2131      *
2132      * @param fd the fixed date
2133      */
2134     private static LocalGregorianCalendar.Date getCalendarDate(long fd) {
2135         LocalGregorianCalendar.Date d = jcal.newCalendarDate(TimeZone.NO_TIMEZONE);
2136         jcal.getCalendarDateFromFixedDate(d, fd);
2137         return d;
2138     }
2139 
2140     /**
2141      * Returns the length of the specified month in the specified
2142      * Gregorian year. The year number must be normalized.
2143      *
2144      * @see GregorianCalendar#isLeapYear(int)
2145      */
2146     private int monthLength(int month, int gregorianYear) {
2147         return CalendarUtils.isGregorianLeapYear(gregorianYear) ?
2148             GregorianCalendar.LEAP_MONTH_LENGTH[month] : GregorianCalendar.MONTH_LENGTH[month];
2149     }
2150 
2151     /**
2152      * Returns the length of the specified month in the year provided
2153      * by internalGet(YEAR).
2154      *
2155      * @see GregorianCalendar#isLeapYear(int)
2156      */
2157     private int monthLength(int month) {
2158         assert jdate.isNormalized();
2159         return jdate.isLeapYear() ?
2160             GregorianCalendar.LEAP_MONTH_LENGTH[month] : GregorianCalendar.MONTH_LENGTH[month];
2161     }
2162 
2163     private int actualMonthLength() {
2164         int length = jcal.getMonthLength(jdate);
2165         int eraIndex = getTransitionEraIndex(jdate);
2166         if (eraIndex == -1) {
2167             long transitionFixedDate = sinceFixedDates[eraIndex];
2168             CalendarDate d = eras[eraIndex].getSinceDate();
2169             if (transitionFixedDate <= cachedFixedDate) {
2170                 length -= d.getDayOfMonth() - 1;
2171             } else {
2172                 length = d.getDayOfMonth() - 1;
2173             }
2174         }
2175         return length;