From e5894de17d2e2eb563b034632664847e871b9b09 Mon Sep 17 00:00:00 2001 From: okutsu Date: Sat, 3 Dec 2011 10:58:19 +0900 Subject: [PATCH] 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util Reviewed-by: lancea, naoto --- src/share/classes/java/util/Date.java | 10 +- .../classes/java/util/GregorianCalendar.java | 80 +++++++------- .../java/util/JapaneseImperialCalendar.java | 100 +++++++++--------- .../classes/java/util/ResourceBundle.java | 88 ++++++++------- .../sun/util/calendar/BaseCalendar.java | 7 +- .../sun/util/calendar/CalendarSystem.java | 17 +-- .../util/calendar/LocalGregorianCalendar.java | 7 +- .../classes/sun/util/calendar/ZoneInfo.java | 13 ++- .../sun/util/calendar/ZoneInfoFile.java | 27 ++--- .../resources/OpenListResourceBundle.java | 11 +- .../util/resources/TimeZoneNamesBundle.java | 11 +- 11 files changed, 189 insertions(+), 182 deletions(-) diff --git a/src/share/classes/java/util/Date.java b/src/share/classes/java/util/Date.java index e5e5e1445..773520941 100644 --- a/src/share/classes/java/util/Date.java +++ b/src/share/classes/java/util/Date.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -770,7 +770,7 @@ public class Date */ @Deprecated public int getDay() { - return normalize().getDayOfWeek() - gcal.SUNDAY; + return normalize().getDayOfWeek() - BaseCalendar.SUNDAY; } /** @@ -1027,7 +1027,7 @@ public class Date BaseCalendar.Date date = normalize(); StringBuilder sb = new StringBuilder(28); int index = date.getDayOfWeek(); - if (index == gcal.SUNDAY) { + if (index == BaseCalendar.SUNDAY) { index = 8; } convertToAbbr(sb, wtb[index]).append(' '); // EEE @@ -1039,7 +1039,7 @@ public class Date CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss TimeZone zi = date.getZone(); if (zi != null) { - sb.append(zi.getDisplayName(date.isDaylightTime(), zi.SHORT, Locale.US)); // zzz + sb.append(zi.getDisplayName(date.isDaylightTime(), TimeZone.SHORT, Locale.US)); // zzz } else { sb.append("GMT"); } @@ -1237,7 +1237,7 @@ public class Date } GregorianCalendar gc = new GregorianCalendar(tz); gc.clear(); - gc.set(gc.MILLISECOND, ms); + gc.set(GregorianCalendar.MILLISECOND, ms); gc.set(y, m-1, d, hh, mm, ss); fastTime = gc.getTimeInMillis(); BaseCalendar cal = getCalendarSystem(fastTime); diff --git a/src/share/classes/java/util/GregorianCalendar.java b/src/share/classes/java/util/GregorianCalendar.java index 3a6d20325..586524b3b 100644 --- a/src/share/classes/java/util/GregorianCalendar.java +++ b/src/share/classes/java/util/GregorianCalendar.java @@ -947,7 +947,7 @@ public class GregorianCalendar extends Calendar { } if (month >= 0) { - set(MONTH, (int) (month % 12)); + set(MONTH, month % 12); } else { // month < 0 month %= 12; @@ -1313,8 +1313,8 @@ public class GregorianCalendar extends Calendar { } // the first day of week of the month. - long monthDay1st = calsys.getDayOfWeekDateOnOrBefore(month1 + 6, - getFirstDayOfWeek()); + long monthDay1st = BaseCalendar.getDayOfWeekDateOnOrBefore(month1 + 6, + getFirstDayOfWeek()); // if the week has enough days to form a week, the // week starts from the previous month. if ((int)(monthDay1st - month1) >= getMinimalDaysInFirstWeek()) { @@ -1407,7 +1407,7 @@ public class GregorianCalendar extends Calendar { return; } long fd = getCurrentFixedDate(); - long dowFirst = calsys.getDayOfWeekDateOnOrBefore(fd, getFirstDayOfWeek()); + long dowFirst = BaseCalendar.getDayOfWeekDateOnOrBefore(fd, getFirstDayOfWeek()); fd += amount; if (fd < dowFirst) { fd += 7; @@ -1926,7 +1926,7 @@ public class GregorianCalendar extends Calendar { * Returns the millisecond offset from the beginning of this * year. This Calendar object must have been normalized. */ - private final long getYearOffsetInMillis() { + private long getYearOffsetInMillis() { long t = (internalGet(DAY_OF_YEAR) - 1) * 24; t += internalGet(HOUR_OF_DAY); t *= 60; @@ -2485,8 +2485,8 @@ public class GregorianCalendar extends Calendar { if (cdate.isLeapYear()) { nextJan1++; } - long nextJan1st = calsys.getDayOfWeekDateOnOrBefore(nextJan1 + 6, - getFirstDayOfWeek()); + long nextJan1st = BaseCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, + getFirstDayOfWeek()); int ndays = (int)(nextJan1st - nextJan1); if (ndays >= getMinimalDaysInFirstWeek() && fixedDate >= (nextJan1st - 7)) { // The first days forms a week in which the date is included. @@ -2518,8 +2518,8 @@ public class GregorianCalendar extends Calendar { calForJan1 = gcal; } - long nextJan1st = calForJan1.getDayOfWeekDateOnOrBefore(nextJan1 + 6, - getFirstDayOfWeek()); + long nextJan1st = BaseCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, + getFirstDayOfWeek()); int ndays = (int)(nextJan1st - nextJan1); if (ndays >= getMinimalDaysInFirstWeek() && fixedDate >= (nextJan1st - 7)) { // The first days forms a week in which the date is included. @@ -2543,11 +2543,11 @@ public class GregorianCalendar extends Calendar { * @param fixedDate the fixed date of the last day of the period * @return the number of weeks of the given period */ - private final int getWeekNumber(long fixedDay1, long fixedDate) { + private int getWeekNumber(long fixedDay1, long fixedDate) { // We can always use `gcal' since Julian and Gregorian are the // same thing for this calculation. - long fixedDay1st = gcal.getDayOfWeekDateOnOrBefore(fixedDay1 + 6, - getFirstDayOfWeek()); + long fixedDay1st = Gregorian.getDayOfWeekDateOnOrBefore(fixedDay1 + 6, + getFirstDayOfWeek()); int ndays = (int)(fixedDay1st - fixedDay1); assert ndays <= 7; if (ndays >= getMinimalDaysInFirstWeek()) { @@ -2818,16 +2818,16 @@ public class GregorianCalendar extends Calendar { } } else { if (isFieldSet(fieldMask, WEEK_OF_MONTH)) { - long firstDayOfWeek = cal.getDayOfWeekDateOnOrBefore(fixedDate + 6, - getFirstDayOfWeek()); + long firstDayOfWeek = BaseCalendar.getDayOfWeekDateOnOrBefore(fixedDate + 6, + getFirstDayOfWeek()); // If we have enough days in the first week, then // move to the previous week. if ((firstDayOfWeek - fixedDate) >= getMinimalDaysInFirstWeek()) { firstDayOfWeek -= 7; } if (isFieldSet(fieldMask, DAY_OF_WEEK)) { - firstDayOfWeek = cal.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, - internalGet(DAY_OF_WEEK)); + firstDayOfWeek = BaseCalendar.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, + internalGet(DAY_OF_WEEK)); } // In lenient mode, we treat days of the previous // months as a part of the specified @@ -2850,15 +2850,15 @@ public class GregorianCalendar extends Calendar { dowim = 1; } if (dowim >= 0) { - fixedDate = cal.getDayOfWeekDateOnOrBefore(fixedDate + (7 * dowim) - 1, - dayOfWeek); + fixedDate = BaseCalendar.getDayOfWeekDateOnOrBefore(fixedDate + (7 * dowim) - 1, + dayOfWeek); } else { // Go to the first day of the next week of // the specified week boundary. int lastDate = monthLength(month, year) + (7 * (dowim + 1)); // Then, get the day of week date on or before the last date. - fixedDate = cal.getDayOfWeekDateOnOrBefore(fixedDate + lastDate - 1, - dayOfWeek); + fixedDate = BaseCalendar.getDayOfWeekDateOnOrBefore(fixedDate + lastDate - 1, + dayOfWeek); } } } @@ -2877,8 +2877,8 @@ public class GregorianCalendar extends Calendar { fixedDate += internalGet(DAY_OF_YEAR); fixedDate--; } else { - long firstDayOfWeek = cal.getDayOfWeekDateOnOrBefore(fixedDate + 6, - getFirstDayOfWeek()); + long firstDayOfWeek = BaseCalendar.getDayOfWeekDateOnOrBefore(fixedDate + 6, + getFirstDayOfWeek()); // If we have enough days in the first week, then move // to the previous week. if ((firstDayOfWeek - fixedDate) >= getMinimalDaysInFirstWeek()) { @@ -2887,8 +2887,8 @@ public class GregorianCalendar extends Calendar { if (isFieldSet(fieldMask, DAY_OF_WEEK)) { int dayOfWeek = internalGet(DAY_OF_WEEK); if (dayOfWeek != getFirstDayOfWeek()) { - firstDayOfWeek = cal.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, - dayOfWeek); + firstDayOfWeek = BaseCalendar.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, + dayOfWeek); } } fixedDate = firstDayOfWeek + 7 * ((long)internalGet(WEEK_OF_YEAR) - 1); @@ -2903,7 +2903,7 @@ public class GregorianCalendar extends Calendar { * in sync). Otherwise, a cloned object is returned after calling * complete() in lenient mode. */ - private final GregorianCalendar getNormalizedCalendar() { + private GregorianCalendar getNormalizedCalendar() { GregorianCalendar gc; if (isFullyNormalized()) { gc = this; @@ -2920,7 +2920,7 @@ public class GregorianCalendar extends Calendar { * Returns the Julian calendar system instance (singleton). 'jcal' * and 'jeras' are set upon the return. */ - synchronized private static final BaseCalendar getJulianCalendarSystem() { + synchronized private static BaseCalendar getJulianCalendarSystem() { if (jcal == null) { jcal = (JulianCalendar) CalendarSystem.forName("julian"); jeras = jcal.getEras(); @@ -2958,7 +2958,7 @@ public class GregorianCalendar extends Calendar { * or Julian). * @param fixedDate the fixed date representation of the date */ - private final long getFixedDateJan1(BaseCalendar.Date date, long fixedDate) { + private long getFixedDateJan1(BaseCalendar.Date date, long fixedDate) { assert date.getNormalizedYear() == gregorianCutoverYear || date.getNormalizedYear() == gregorianCutoverYearJulian; if (gregorianCutoverYear != gregorianCutoverYearJulian) { @@ -2984,7 +2984,7 @@ public class GregorianCalendar extends Calendar { * or Julian). * @param fixedDate the fixed date representation of the date */ - private final long getFixedDateMonth1(BaseCalendar.Date date, long fixedDate) { + private long getFixedDateMonth1(BaseCalendar.Date date, long fixedDate) { assert date.getNormalizedYear() == gregorianCutoverYear || date.getNormalizedYear() == gregorianCutoverYearJulian; BaseCalendar.Date gCutover = getGregorianCutoverDate(); @@ -3023,7 +3023,7 @@ public class GregorianCalendar extends Calendar { * * @param fd the fixed date */ - private final BaseCalendar.Date getCalendarDate(long fd) { + private BaseCalendar.Date getCalendarDate(long fd) { BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem(); BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE); cal.getCalendarDateFromFixedDate(d, fd); @@ -3034,7 +3034,7 @@ public class GregorianCalendar extends Calendar { * Returns the Gregorian cutover date as a BaseCalendar.Date. The * date is a Gregorian date. */ - private final BaseCalendar.Date getGregorianCutoverDate() { + private BaseCalendar.Date getGregorianCutoverDate() { return getCalendarDate(gregorianCutoverDate); } @@ -3042,7 +3042,7 @@ public class GregorianCalendar extends Calendar { * Returns the day before the Gregorian cutover date as a * BaseCalendar.Date. The date is a Julian date. */ - private final BaseCalendar.Date getLastJulianDate() { + private BaseCalendar.Date getLastJulianDate() { return getCalendarDate(gregorianCutoverDate - 1); } @@ -3052,7 +3052,7 @@ public class GregorianCalendar extends Calendar { * * @see #isLeapYear(int) */ - private final int monthLength(int month, int year) { + private int monthLength(int month, int year) { return isLeapYear(year) ? LEAP_MONTH_LENGTH[month] : MONTH_LENGTH[month]; } @@ -3062,7 +3062,7 @@ public class GregorianCalendar extends Calendar { * * @see #isLeapYear(int) */ - private final int monthLength(int month) { + private int monthLength(int month) { int year = internalGet(YEAR); if (internalGetEra() == BCE) { year = 1 - year; @@ -3070,7 +3070,7 @@ public class GregorianCalendar extends Calendar { return monthLength(month, year); } - private final int actualMonthLength() { + private int actualMonthLength() { int year = cdate.getNormalizedYear(); if (year != gregorianCutoverYear && year != gregorianCutoverYearJulian) { return calsys.getMonthLength(cdate); @@ -3094,7 +3094,7 @@ public class GregorianCalendar extends Calendar { * Returns the length (in days) of the specified year. The year * must be normalized. */ - private final int yearLength(int year) { + private int yearLength(int year) { return isLeapYear(year) ? 366 : 365; } @@ -3102,7 +3102,7 @@ public class GregorianCalendar extends Calendar { * Returns the length (in days) of the year provided by * internalGet(YEAR). */ - private final int yearLength() { + private int yearLength() { int year = internalGet(YEAR); if (internalGetEra() == BCE) { year = 1 - year; @@ -3116,7 +3116,7 @@ public class GregorianCalendar extends Calendar { * 3, we want it to go to Feb 28. Adjustments which might run into this * problem call this method to retain the proper month. */ - private final void pinDayOfMonth() { + private void pinDayOfMonth() { int year = internalGet(YEAR); int monthLen; if (year > gregorianCutoverYear || year < gregorianCutoverYearJulian) { @@ -3135,14 +3135,14 @@ public class GregorianCalendar extends Calendar { * Returns the fixed date value of this object. The time value and * calendar fields must be in synch. */ - private final long getCurrentFixedDate() { + private long getCurrentFixedDate() { return (calsys == gcal) ? cachedFixedDate : calsys.getFixedDate(cdate); } /** * Returns the new value after 'roll'ing the specified value and amount. */ - private static final int getRolledValue(int value, int amount, int min, int max) { + private static int getRolledValue(int value, int amount, int min, int max) { assert value >= min && value <= max; int range = max - min + 1; amount %= range; @@ -3160,7 +3160,7 @@ public class GregorianCalendar extends Calendar { * Returns the ERA. We need a special method for this because the * default ERA is CE, but a zero (unset) ERA is BCE. */ - private final int internalGetEra() { + private int internalGetEra() { return isSet(ERA) ? internalGet(ERA) : CE; } diff --git a/src/share/classes/java/util/JapaneseImperialCalendar.java b/src/share/classes/java/util/JapaneseImperialCalendar.java index c18c0bb97..940ab6210 100644 --- a/src/share/classes/java/util/JapaneseImperialCalendar.java +++ b/src/share/classes/java/util/JapaneseImperialCalendar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -260,8 +260,9 @@ class JapaneseImperialCalendar extends Calendar { // max value could be one year short. For example, if it's // Showa 63 January 8, 63 is the actual max value since // Showa 64 January 8 doesn't exist. - if (!(lgd.getMonth() == BaseCalendar.JANUARY && lgd.getDayOfMonth() == 1)) + if (!(lgd.getMonth() == BaseCalendar.JANUARY && lgd.getDayOfMonth() == 1)) { y--; + } year = Math.min(y, year); } LEAST_MAX_VALUES[YEAR] = year; // Max year could be smaller than this value. @@ -294,7 +295,7 @@ class JapaneseImperialCalendar extends Calendar { * @param zone the given time zone. * @param aLocale the given locale. */ - public JapaneseImperialCalendar(TimeZone zone, Locale aLocale) { + JapaneseImperialCalendar(TimeZone zone, Locale aLocale) { super(zone, aLocale); jdate = jcal.newCalendarDate(zone); setTimeInMillis(System.currentTimeMillis()); @@ -792,8 +793,8 @@ class JapaneseImperialCalendar extends Calendar { } // the first day of week of the month. - long monthDay1st = jcal.getDayOfWeekDateOnOrBefore(month1 + 6, - getFirstDayOfWeek()); + long monthDay1st = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(month1 + 6, + getFirstDayOfWeek()); // if the week has enough days to form a week, the // week starts from the previous month. if ((int)(monthDay1st - month1) >= getMinimalDaysInFirstWeek()) { @@ -884,7 +885,7 @@ class JapaneseImperialCalendar extends Calendar { return; } long fd = cachedFixedDate; - long dowFirst = jcal.getDayOfWeekDateOnOrBefore(fd, getFirstDayOfWeek()); + long dowFirst = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(fd, getFirstDayOfWeek()); fd += amount; if (fd < dowFirst) { fd += 7; @@ -963,8 +964,9 @@ class JapaneseImperialCalendar extends Calendar { Era era = eras[index]; name = (style == SHORT) ? era.getAbbreviation() : era.getName(); } else { - if (field == DAY_OF_WEEK) + if (field == DAY_OF_WEEK) { --index; + } name = strings[index]; } } @@ -1000,7 +1002,7 @@ class JapaneseImperialCalendar extends Calendar { private Map getDisplayNamesImpl(int field, int style, Locale locale) { ResourceBundle rb = LocaleData.getDateFormatData(locale); String key = getKey(field, style); - Map map = new HashMap(); + Map map = new HashMap<>(); if (key != null) { String[] strings = rb.getStringArray(key); if (field == YEAR) { @@ -1392,8 +1394,8 @@ class JapaneseImperialCalendar extends Calendar { jcal.normalize(jd); long jan1 = jcal.getFixedDate(d); long nextJan1 = jcal.getFixedDate(jd); - long nextJan1st = jcal.getDayOfWeekDateOnOrBefore(nextJan1 + 6, - getFirstDayOfWeek()); + long nextJan1st = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, + getFirstDayOfWeek()); int ndays = (int)(nextJan1st - nextJan1); if (ndays >= getMinimalDaysInFirstWeek()) { nextJan1st -= 7; @@ -1523,7 +1525,7 @@ class JapaneseImperialCalendar extends Calendar { * beyond the limit. The given CalendarDate object must have been * normalized before calling this method. */ - private final long getYearOffsetInMillis(CalendarDate date) { + private long getYearOffsetInMillis(CalendarDate date) { long t = (jcal.getDayOfYear(date) - 1) * ONE_DAY; return t + date.getTimeOfDay() - date.getZoneOffset(); } @@ -1755,7 +1757,7 @@ class JapaneseImperialCalendar extends Calendar { d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth()); } } else { - d.setMonth(jcal.JANUARY).setDayOfMonth(1); + d.setMonth(LocalGregorianCalendar.JANUARY).setDayOfMonth(1); } jcal.normalize(d); prevJan1 = jcal.getFixedDate(d); @@ -1780,8 +1782,8 @@ class JapaneseImperialCalendar extends Calendar { if (jdate.isLeapYear()) { nextJan1++; } - long nextJan1st = jcal.getDayOfWeekDateOnOrBefore(nextJan1 + 6, - getFirstDayOfWeek()); + long nextJan1st = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, + getFirstDayOfWeek()); int ndays = (int)(nextJan1st - nextJan1); if (ndays >= getMinimalDaysInFirstWeek() && fixedDate >= (nextJan1st - 7)) { // The first days forms a week in which the date is included. @@ -1793,7 +1795,7 @@ class JapaneseImperialCalendar extends Calendar { long nextJan1; if (jdate.getYear() == 1) { d.addYear(+1); - d.setMonth(jcal.JANUARY).setDayOfMonth(1); + d.setMonth(LocalGregorianCalendar.JANUARY).setDayOfMonth(1); nextJan1 = jcal.getFixedDate(d); } else { int nextEraIndex = getEraIndex(d) + 1; @@ -1803,8 +1805,8 @@ class JapaneseImperialCalendar extends Calendar { jcal.normalize(d); nextJan1 = jcal.getFixedDate(d); } - long nextJan1st = jcal.getDayOfWeekDateOnOrBefore(nextJan1 + 6, - getFirstDayOfWeek()); + long nextJan1st = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, + getFirstDayOfWeek()); int ndays = (int)(nextJan1st - nextJan1); if (ndays >= getMinimalDaysInFirstWeek() && fixedDate >= (nextJan1st - 7)) { // The first days forms a week in which the date is included. @@ -1828,11 +1830,11 @@ class JapaneseImperialCalendar extends Calendar { * @param fixedDate the fixed date of the last day of the period * @return the number of weeks of the given period */ - private final int getWeekNumber(long fixedDay1, long fixedDate) { + private int getWeekNumber(long fixedDay1, long fixedDate) { // We can always use `jcal' since Julian and Gregorian are the // same thing for this calculation. - long fixedDay1st = jcal.getDayOfWeekDateOnOrBefore(fixedDay1 + 6, - getFirstDayOfWeek()); + long fixedDay1st = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(fixedDay1 + 6, + getFirstDayOfWeek()); int ndays = (int)(fixedDay1st - fixedDay1); assert ndays <= 7; if (ndays >= getMinimalDaysInFirstWeek()) { @@ -2026,10 +2028,12 @@ class JapaneseImperialCalendar extends Calendar { if (year == MIN_VALUES[YEAR]) { CalendarDate dx = jcal.getCalendarDate(Long.MIN_VALUE, getZone()); int m = dx.getMonth() - 1; - if (month < m) + if (month < m) { month = m; - if (month == m) + } + if (month == m) { firstDayOfMonth = dx.getDayOfMonth(); + } } LocalGregorianCalendar.Date date = jcal.newCalendarDate(TimeZone.NO_TIMEZONE); @@ -2058,16 +2062,16 @@ class JapaneseImperialCalendar extends Calendar { } } else { if (isFieldSet(fieldMask, WEEK_OF_MONTH)) { - long firstDayOfWeek = jcal.getDayOfWeekDateOnOrBefore(fixedDate + 6, - getFirstDayOfWeek()); + long firstDayOfWeek = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(fixedDate + 6, + getFirstDayOfWeek()); // If we have enough days in the first week, then // move to the previous week. if ((firstDayOfWeek - fixedDate) >= getMinimalDaysInFirstWeek()) { firstDayOfWeek -= 7; } if (isFieldSet(fieldMask, DAY_OF_WEEK)) { - firstDayOfWeek = jcal.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, - internalGet(DAY_OF_WEEK)); + firstDayOfWeek = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, + internalGet(DAY_OF_WEEK)); } // In lenient mode, we treat days of the previous // months as a part of the specified @@ -2090,15 +2094,15 @@ class JapaneseImperialCalendar extends Calendar { dowim = 1; } if (dowim >= 0) { - fixedDate = jcal.getDayOfWeekDateOnOrBefore(fixedDate + (7 * dowim) - 1, - dayOfWeek); + fixedDate = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(fixedDate + (7 * dowim) - 1, + dayOfWeek); } else { // Go to the first day of the next week of // the specified week boundary. int lastDate = monthLength(month, year) + (7 * (dowim + 1)); // Then, get the day of week date on or before the last date. - fixedDate = jcal.getDayOfWeekDateOnOrBefore(fixedDate + lastDate - 1, - dayOfWeek); + fixedDate = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(fixedDate + lastDate - 1, + dayOfWeek); } } } @@ -2112,8 +2116,8 @@ class JapaneseImperialCalendar extends Calendar { fixedDate += internalGet(DAY_OF_YEAR); fixedDate--; } else { - long firstDayOfWeek = jcal.getDayOfWeekDateOnOrBefore(fixedDate + 6, - getFirstDayOfWeek()); + long firstDayOfWeek = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(fixedDate + 6, + getFirstDayOfWeek()); // If we have enough days in the first week, then move // to the previous week. if ((firstDayOfWeek - fixedDate) >= getMinimalDaysInFirstWeek()) { @@ -2122,8 +2126,8 @@ class JapaneseImperialCalendar extends Calendar { if (isFieldSet(fieldMask, DAY_OF_WEEK)) { int dayOfWeek = internalGet(DAY_OF_WEEK); if (dayOfWeek != getFirstDayOfWeek()) { - firstDayOfWeek = jcal.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, - dayOfWeek); + firstDayOfWeek = LocalGregorianCalendar.getDayOfWeekDateOnOrBefore(firstDayOfWeek + 6, + dayOfWeek); } } fixedDate = firstDayOfWeek + 7 * ((long)internalGet(WEEK_OF_YEAR) - 1); @@ -2140,7 +2144,7 @@ class JapaneseImperialCalendar extends Calendar { * calculated. The date has to be in the cut-over year. * @param fixedDate the fixed date representation of the date */ - private final long getFixedDateJan1(LocalGregorianCalendar.Date date, long fixedDate) { + private long getFixedDateJan1(LocalGregorianCalendar.Date date, long fixedDate) { Era era = date.getEra(); if (date.getEra() != null && date.getYear() == 1) { for (int eraIndex = getEraIndex(date); eraIndex > 0; eraIndex--) { @@ -2154,7 +2158,7 @@ class JapaneseImperialCalendar extends Calendar { } } CalendarDate d = gcal.newCalendarDate(TimeZone.NO_TIMEZONE); - d.setDate(date.getNormalizedYear(), gcal.JANUARY, 1); + d.setDate(date.getNormalizedYear(), Gregorian.JANUARY, 1); return gcal.getFixedDate(d); } @@ -2166,7 +2170,7 @@ class JapaneseImperialCalendar extends Calendar { * calculated. The date must be in the era transition year. * @param fixedDate the fixed date representation of the date */ - private final long getFixedDateMonth1(LocalGregorianCalendar.Date date, + private long getFixedDateMonth1(LocalGregorianCalendar.Date date, long fixedDate) { int eraIndex = getTransitionEraIndex(date); if (eraIndex != -1) { @@ -2187,7 +2191,7 @@ class JapaneseImperialCalendar extends Calendar { * * @param fd the fixed date */ - private static final LocalGregorianCalendar.Date getCalendarDate(long fd) { + private static LocalGregorianCalendar.Date getCalendarDate(long fd) { LocalGregorianCalendar.Date d = jcal.newCalendarDate(TimeZone.NO_TIMEZONE); jcal.getCalendarDateFromFixedDate(d, fd); return d; @@ -2199,7 +2203,7 @@ class JapaneseImperialCalendar extends Calendar { * * @see #isLeapYear(int) */ - private final int monthLength(int month, int gregorianYear) { + private int monthLength(int month, int gregorianYear) { return CalendarUtils.isGregorianLeapYear(gregorianYear) ? GregorianCalendar.LEAP_MONTH_LENGTH[month] : GregorianCalendar.MONTH_LENGTH[month]; } @@ -2210,13 +2214,13 @@ class JapaneseImperialCalendar extends Calendar { * * @see #isLeapYear(int) */ - private final int monthLength(int month) { + private int monthLength(int month) { assert jdate.isNormalized(); return jdate.isLeapYear() ? GregorianCalendar.LEAP_MONTH_LENGTH[month] : GregorianCalendar.MONTH_LENGTH[month]; } - private final int actualMonthLength() { + private int actualMonthLength() { int length = jcal.getMonthLength(jdate); int eraIndex = getTransitionEraIndex(jdate); if (eraIndex == -1) { @@ -2239,7 +2243,7 @@ class JapaneseImperialCalendar extends Calendar { * January 3, then the era index for Heisei is returned. If the * given date is not in any transition month, then -1 is returned. */ - private static final int getTransitionEraIndex(LocalGregorianCalendar.Date date) { + private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) { int eraIndex = getEraIndex(date); CalendarDate transitionDate = eras[eraIndex].getSinceDate(); if (transitionDate.getYear() == date.getNormalizedYear() && @@ -2256,7 +2260,7 @@ class JapaneseImperialCalendar extends Calendar { return -1; } - private final boolean isTransitionYear(int normalizedYear) { + private boolean isTransitionYear(int normalizedYear) { for (int i = eras.length - 1; i > 0; i--) { int transitionYear = eras[i].getSinceDate().getYear(); if (normalizedYear == transitionYear) { @@ -2269,7 +2273,7 @@ class JapaneseImperialCalendar extends Calendar { return false; } - private static final int getEraIndex(LocalGregorianCalendar.Date date) { + private static int getEraIndex(LocalGregorianCalendar.Date date) { Era era = date.getEra(); for (int i = eras.length - 1; i > 0; i--) { if (eras[i] == era) { @@ -2284,7 +2288,7 @@ class JapaneseImperialCalendar extends Calendar { * in sync). Otherwise, a cloned object is returned after calling * complete() in lenient mode. */ - private final JapaneseImperialCalendar getNormalizedCalendar() { + private JapaneseImperialCalendar getNormalizedCalendar() { JapaneseImperialCalendar jc; if (isFullyNormalized()) { jc = this; @@ -2303,7 +2307,7 @@ class JapaneseImperialCalendar extends Calendar { * 3, we want it to go to Feb 28. Adjustments which might run into this * problem call this method to retain the proper month. */ - private final void pinDayOfMonth(LocalGregorianCalendar.Date date) { + private void pinDayOfMonth(LocalGregorianCalendar.Date date) { int year = date.getYear(); int dom = date.getDayOfMonth(); if (year != getMinimum(YEAR)) { @@ -2347,7 +2351,7 @@ class JapaneseImperialCalendar extends Calendar { /** * Returns the new value after 'roll'ing the specified value and amount. */ - private static final int getRolledValue(int value, int amount, int min, int max) { + private static int getRolledValue(int value, int amount, int min, int max) { assert value >= min && value <= max; int range = max - min + 1; amount %= range; @@ -2365,7 +2369,7 @@ class JapaneseImperialCalendar extends Calendar { * Returns the ERA. We need a special method for this because the * default ERA is the current era, but a zero (unset) ERA means before Meiji. */ - private final int internalGetEra() { + private int internalGetEra() { return isSet(ERA) ? internalGet(ERA) : eras.length - 1; } diff --git a/src/share/classes/java/util/ResourceBundle.java b/src/share/classes/java/util/ResourceBundle.java index a4a4d55a1..c7b425db7 100644 --- a/src/share/classes/java/util/ResourceBundle.java +++ b/src/share/classes/java/util/ResourceBundle.java @@ -294,7 +294,7 @@ public abstract class ResourceBundle { /** * Queue for reference objects referring to class loaders or bundles. */ - private static final ReferenceQueue referenceQueue = new ReferenceQueue(); + private static final ReferenceQueue referenceQueue = new ReferenceQueue<>(); /** * The parent bundle of this bundle. @@ -389,12 +389,13 @@ public abstract class ResourceBundle { if (parent != null) { obj = parent.getObject(key); } - if (obj == null) + if (obj == null) { throw new MissingResourceException("Can't find resource for bundle " +this.getClass().getName() +", key "+key, this.getClass().getName(), key); + } } return obj; } @@ -418,7 +419,7 @@ public abstract class ResourceBundle { private static ClassLoader getLoader() { Class[] stack = getClassContext(); /* Magic number 2 identifies our caller's caller */ - Class c = stack[2]; + Class c = stack[2]; ClassLoader cl = (c == null) ? null : c.getClassLoader(); if (cl == null) { // When the caller's loader is the boot class loader, cl is null @@ -488,7 +489,7 @@ public abstract class ResourceBundle { * null, but the base name and the locale must have a non-null * value. */ - private static final class CacheKey implements Cloneable { + private static class CacheKey implements Cloneable { // These three are the actual keys for lookup in Map. private String name; private Locale locale; @@ -583,8 +584,7 @@ public abstract class ResourceBundle { // treat it as unequal && (loader != null) && (loader == otherEntry.loaderRef.get()); - } catch (NullPointerException e) { - } catch (ClassCastException e) { + } catch ( NullPointerException | ClassCastException e) { } return false; } @@ -669,11 +669,11 @@ public abstract class ResourceBundle { * garbage collected when nobody else is using them. The ResourceBundle * class has no reason to keep class loaders alive. */ - private static final class LoaderReference extends WeakReference - implements CacheKeyReference { + private static class LoaderReference extends WeakReference + implements CacheKeyReference { private CacheKey cacheKey; - LoaderReference(ClassLoader referent, ReferenceQueue q, CacheKey key) { + LoaderReference(ClassLoader referent, ReferenceQueue q, CacheKey key) { super(referent, q); cacheKey = key; } @@ -687,11 +687,11 @@ public abstract class ResourceBundle { * References to bundles are soft references so that they can be garbage * collected when they have no hard references. */ - private static final class BundleReference extends SoftReference - implements CacheKeyReference { + private static class BundleReference extends SoftReference + implements CacheKeyReference { private CacheKey cacheKey; - BundleReference(ResourceBundle referent, ReferenceQueue q, CacheKey key) { + BundleReference(ResourceBundle referent, ReferenceQueue q, CacheKey key) { super(referent, q); cacheKey = key; } @@ -1331,8 +1331,8 @@ public abstract class ResourceBundle { * Checks if the given List is not null, not empty, * not having null in its elements. */ - private static final boolean checkList(List a) { - boolean valid = (a != null && a.size() != 0); + private static boolean checkList(List a) { + boolean valid = (a != null && !a.isEmpty()); if (valid) { int size = a.size(); for (int i = 0; valid && i < size; i++) { @@ -1342,12 +1342,12 @@ public abstract class ResourceBundle { return valid; } - private static final ResourceBundle findBundle(CacheKey cacheKey, - List candidateLocales, - List formats, - int index, - Control control, - ResourceBundle baseBundle) { + private static ResourceBundle findBundle(CacheKey cacheKey, + List candidateLocales, + List formats, + int index, + Control control, + ResourceBundle baseBundle) { Locale targetLocale = candidateLocales.get(index); ResourceBundle parent = null; if (index != candidateLocales.size() - 1) { @@ -1419,10 +1419,10 @@ public abstract class ResourceBundle { return parent; } - private static final ResourceBundle loadBundle(CacheKey cacheKey, - List formats, - Control control, - boolean reload) { + private static ResourceBundle loadBundle(CacheKey cacheKey, + List formats, + Control control, + boolean reload) { // Here we actually load the bundle in the order of formats // specified by the getFormats() value. @@ -1459,7 +1459,7 @@ public abstract class ResourceBundle { return bundle; } - private static final boolean isValidBundle(ResourceBundle bundle) { + private static boolean isValidBundle(ResourceBundle bundle) { return bundle != null && bundle != NONEXISTENT_BUNDLE; } @@ -1467,7 +1467,7 @@ public abstract class ResourceBundle { * Determines whether any of resource bundles in the parent chain, * including the leaf, have expired. */ - private static final boolean hasValidParentChain(ResourceBundle bundle) { + private static boolean hasValidParentChain(ResourceBundle bundle) { long now = System.currentTimeMillis(); while (bundle != null) { if (bundle.expired) { @@ -1488,9 +1488,9 @@ public abstract class ResourceBundle { /** * Throw a MissingResourceException with proper message */ - private static final void throwMissingResourceException(String baseName, - Locale locale, - Throwable cause) { + private static void throwMissingResourceException(String baseName, + Locale locale, + Throwable cause) { // If the cause is a MissingResourceException, avoid creating // a long chain. (6355009) if (cause instanceof MissingResourceException) { @@ -1513,8 +1513,8 @@ public abstract class ResourceBundle { * cache or its parent has expired. bundle.expire is true * upon return if the bundle in the cache has expired. */ - private static final ResourceBundle findBundleInCache(CacheKey cacheKey, - Control control) { + private static ResourceBundle findBundleInCache(CacheKey cacheKey, + Control control) { BundleReference bundleRef = cacheList.get(cacheKey); if (bundleRef == null) { return null; @@ -1620,9 +1620,9 @@ public abstract class ResourceBundle { * the bundle before this call, the one found in the cache is * returned. */ - private static final ResourceBundle putBundleInCache(CacheKey cacheKey, - ResourceBundle bundle, - Control control) { + private static ResourceBundle putBundleInCache(CacheKey cacheKey, + ResourceBundle bundle, + Control control) { setExpirationTime(cacheKey, control); if (cacheKey.expirationTime != Control.TTL_DONT_CACHE) { CacheKey key = (CacheKey) cacheKey.clone(); @@ -1653,7 +1653,7 @@ public abstract class ResourceBundle { return bundle; } - private static final void setExpirationTime(CacheKey cacheKey, Control control) { + private static void setExpirationTime(CacheKey cacheKey, Control control) { long ttl = control.getTimeToLive(cacheKey.getName(), cacheKey.getLocale()); if (ttl >= 0) { @@ -2350,18 +2350,27 @@ public abstract class ResourceBundle { if (script.length() == 0 && region.length() > 0) { // Supply script for users who want to use zh_Hans/zh_Hant // as bundle names (recommended for Java7+) - if (region.equals("TW") || region.equals("HK") || region.equals("MO")) { + switch (region) { + case "TW": + case "HK": + case "MO": script = "Hant"; - } else if (region.equals("CN") || region.equals("SG")) { + break; + case "CN": + case "SG": script = "Hans"; + break; } } else if (script.length() > 0 && region.length() == 0) { // Supply region(country) for users who still package Chinese // bundles using old convension. - if (script.equals("Hans")) { + switch (script) { + case "Hans": region = "CN"; - } else if (script.equals("Hant")) { + break; + case "Hant": region = "TW"; + break; } } } @@ -2562,6 +2571,7 @@ public abstract class ResourceBundle { ResourceBundle bundle = null; if (format.equals("java.class")) { try { + @SuppressWarnings("unchecked") Class bundleClass = (Class)loader.loadClass(bundleName); diff --git a/src/share/classes/sun/util/calendar/BaseCalendar.java b/src/share/classes/sun/util/calendar/BaseCalendar.java index 21528dc48..a7e763a0d 100644 --- a/src/share/classes/sun/util/calendar/BaseCalendar.java +++ b/src/share/classes/sun/util/calendar/BaseCalendar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,6 @@ package sun.util.calendar; -import java.util.Locale; import java.util.TimeZone; /** @@ -203,7 +202,7 @@ public abstract class BaseCalendar extends AbstractCalendar { return false; } int dow = bdate.getDayOfWeek(); - if (dow != bdate.FIELD_UNDEFINED && dow != getDayOfWeek(bdate)) { + if (dow != Date.FIELD_UNDEFINED && dow != getDayOfWeek(bdate)) { return false; } @@ -329,7 +328,7 @@ public abstract class BaseCalendar extends AbstractCalendar { } // accepts 0 (December in the previous year) to 12. - private final int getMonthLength(int year, int month) { + private int getMonthLength(int year, int month) { int days = DAYS_IN_MONTH[month]; if (month == FEBRUARY && isLeapYear(year)) { days++; diff --git a/src/share/classes/sun/util/calendar/CalendarSystem.java b/src/share/classes/sun/util/calendar/CalendarSystem.java index ac8564125..fdbdcb070 100644 --- a/src/share/classes/sun/util/calendar/CalendarSystem.java +++ b/src/share/classes/sun/util/calendar/CalendarSystem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,13 +25,6 @@ package sun.util.calendar; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.Set; import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -99,7 +92,7 @@ public abstract class CalendarSystem { }; private static void initNames() { - ConcurrentMap nameMap = new ConcurrentHashMap(); + ConcurrentMap nameMap = new ConcurrentHashMap<>(); // Associate a calendar name with its class name and the // calendar class name with its date class name. @@ -112,7 +105,7 @@ public abstract class CalendarSystem { synchronized (CalendarSystem.class) { if (!initialized) { names = nameMap; - calendars = new ConcurrentHashMap(); + calendars = new ConcurrentHashMap<>(); initialized = true; } } @@ -164,10 +157,10 @@ public abstract class CalendarSystem { cal = LocalGregorianCalendar.getLocalGregorianCalendar(calendarName); } else { try { - Class cl = Class.forName(className); + Class cl = Class.forName(className); cal = (CalendarSystem) cl.newInstance(); } catch (Exception e) { - throw new RuntimeException("internal error", e); + throw new InternalError(e); } } if (cal == null) { diff --git a/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java b/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java index 99da4cd3b..d107a004d 100644 --- a/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java +++ b/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.security.AccessController; -import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; @@ -124,8 +123,8 @@ public class LocalGregorianCalendar extends BaseCalendar { new sun.security.action.GetPropertyAction("java.home")); final String fname = homeDir + File.separator + "lib" + File.separator + "calendars.properties"; - calendarProps = (Properties) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { + calendarProps = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Properties run() throws IOException { Properties props = new Properties(); try (FileInputStream fis = new FileInputStream(fname)) { props.load(fis); @@ -142,7 +141,7 @@ public class LocalGregorianCalendar extends BaseCalendar { if (props == null) { return null; } - List eras = new ArrayList(); + List eras = new ArrayList<>(); StringTokenizer eraTokens = new StringTokenizer(props, ";"); while (eraTokens.hasMoreTokens()) { String items = eraTokens.nextToken().trim(); diff --git a/src/share/classes/sun/util/calendar/ZoneInfo.java b/src/share/classes/sun/util/calendar/ZoneInfo.java index b79e7cc39..975e3ed10 100644 --- a/src/share/classes/sun/util/calendar/ZoneInfo.java +++ b/src/share/classes/sun/util/calendar/ZoneInfo.java @@ -31,7 +31,6 @@ import java.lang.ref.SoftReference; import java.security.AccessController; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -318,7 +317,7 @@ public class ZoneInfo extends TimeZone { return offset; } - private final int getTransitionIndex(long date, int type) { + private int getTransitionIndex(long date, int type) { int low = 0; int high = transitions.length - 1; @@ -572,7 +571,7 @@ public class ZoneInfo extends TimeZone { List excluded = ZoneInfoFile.getExcludedZones(); if (excluded != null) { // List all zones from the idList and excluded lists - List list = new ArrayList(idList.size() + excluded.size()); + List list = new ArrayList<>(idList.size() + excluded.size()); list.addAll(idList); list.addAll(excluded); idList = list; @@ -592,7 +591,7 @@ public class ZoneInfo extends TimeZone { */ public static String[] getAvailableIDs(int rawOffset) { String[] result; - List matched = new ArrayList(); + List matched = new ArrayList<>(); List IDs = ZoneInfoFile.getZoneIDs(); int[] rawOffsets = ZoneInfoFile.getRawOffsets(); @@ -807,7 +806,7 @@ public class ZoneInfo extends TimeZone { return (checksum == ((ZoneInfo)other).checksum); } - private static SoftReference aliasTable; + private static SoftReference> aliasTable; /** * Returns a Map from alias time zone IDs to their standard @@ -820,7 +819,7 @@ public class ZoneInfo extends TimeZone { public synchronized static Map getAliasTable() { Map aliases = null; - SoftReference cache = aliasTable; + SoftReference> cache = aliasTable; if (cache != null) { aliases = cache.get(); if (aliases != null) { @@ -830,7 +829,7 @@ public class ZoneInfo extends TimeZone { aliases = ZoneInfoFile.getZoneAliases(); if (aliases != null) { - aliasTable = new SoftReference(aliases); + aliasTable = new SoftReference<>(aliases); } return aliases; } diff --git a/src/share/classes/sun/util/calendar/ZoneInfoFile.java b/src/share/classes/sun/util/calendar/ZoneInfoFile.java index 891817776..2ad72b0e5 100644 --- a/src/share/classes/sun/util/calendar/ZoneInfoFile.java +++ b/src/share/classes/sun/util/calendar/ZoneInfoFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -573,7 +573,7 @@ public class ZoneInfoFile { synchronized static ZoneInfo addToCache(String id, ZoneInfo zi) { if (zoneInfoObjects == null) { - zoneInfoObjects = new HashMap(); + zoneInfoObjects = new HashMap<>(); } else { ZoneInfo zone = zoneInfoObjects.get(id); if (zone != null) { @@ -758,7 +758,7 @@ public class ZoneInfoFile { case TAG_ZoneIDs: { int n = (buf[index++] << 8) + (buf[index++] & 0xFF); - ids = new ArrayList(n); + ids = new ArrayList<>(n); for (int i = 0; i < n; i++) { byte m = buf[index++]; @@ -777,7 +777,7 @@ public class ZoneInfoFile { System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME); } - zoneIDs = new SoftReference>(ids); + zoneIDs = new SoftReference<>(ids); return ids; } @@ -802,7 +802,7 @@ public class ZoneInfoFile { case TAG_ZoneAliases: { int n = (buf[index++] << 8) + (buf[index++] & 0xFF); - aliases = new HashMap(n); + aliases = new HashMap<>(n); for (int i = 0; i < n; i++) { byte m = buf[index++]; String name = new String(buf, index, m, "UTF-8"); @@ -865,7 +865,7 @@ public class ZoneInfoFile { case TAG_ExcludedZones: { int n = (buf[index++] << 8) + (buf[index++] & 0xFF); - excludeList = new ArrayList(); + excludeList = new ArrayList<>(); for (int i = 0; i < n; i++) { byte m = buf[index++]; String name = new String(buf, index, m, "UTF-8"); @@ -886,7 +886,7 @@ public class ZoneInfoFile { } if (excludeList != null) { - excludedIDs = new SoftReference>(excludeList); + excludedIDs = new SoftReference<>(excludeList); } else { hasNoExcludeList = true; } @@ -935,7 +935,7 @@ public class ZoneInfoFile { System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME); } - rawOffsetIndices = new SoftReference(indices); + rawOffsetIndices = new SoftReference<>(indices); return indices; } @@ -986,7 +986,7 @@ public class ZoneInfoFile { System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME); } - rawOffsets = new SoftReference(offsets); + rawOffsets = new SoftReference<>(offsets); return offsets; } @@ -1022,7 +1022,7 @@ public class ZoneInfoFile { return null; } - zoneInfoMappings = new SoftReference(data); + zoneInfoMappings = new SoftReference<>(data); return data; } @@ -1034,8 +1034,8 @@ public class ZoneInfoFile { byte[] buffer = null; try { - buffer = (byte[]) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { + buffer = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public byte[] run() throws IOException { File file = new File(ziDir, fileName); if (!file.exists() || !file.isFile()) { return null; @@ -1068,4 +1068,7 @@ public class ZoneInfoFile { } return buffer; } + + private ZoneInfoFile() { + } } diff --git a/src/share/classes/sun/util/resources/OpenListResourceBundle.java b/src/share/classes/sun/util/resources/OpenListResourceBundle.java index 86a91f878..f8d48a213 100644 --- a/src/share/classes/sun/util/resources/OpenListResourceBundle.java +++ b/src/share/classes/sun/util/resources/OpenListResourceBundle.java @@ -119,11 +119,12 @@ public abstract class OpenListResourceBundle extends ResourceBundle { * loading. */ private synchronized void loadLookup() { - if (lookup != null) + if (lookup != null) { return; + } Object[][] contents = getContents(); - Map temp = createMap(contents.length); + Map temp = createMap(contents.length); for (int i = 0; i < contents.length; ++i) { // key must be non-null String, value must be non-null String key = (String) contents[i][0]; @@ -140,9 +141,9 @@ public abstract class OpenListResourceBundle extends ResourceBundle { * Lets subclasses provide specialized Map implementations. * Default uses HashMap. */ - protected Map createMap(int size) { - return new HashMap(size); + protected Map createMap(int size) { + return new HashMap<>(size); } - private Map lookup = null; + private Map lookup = null; } diff --git a/src/share/classes/sun/util/resources/TimeZoneNamesBundle.java b/src/share/classes/sun/util/resources/TimeZoneNamesBundle.java index 636012501..3757ed121 100644 --- a/src/share/classes/sun/util/resources/TimeZoneNamesBundle.java +++ b/src/share/classes/sun/util/resources/TimeZoneNamesBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -80,17 +80,16 @@ public abstract class TimeZoneNamesBundle extends OpenListResourceBundle { int clen = contents.length; String[] tmpobj = new String[clen+1]; tmpobj[0] = key; - for (int i = 0; i < clen; i++) { - tmpobj[i+1] = contents[i]; - } + System.arraycopy(contents, 0, tmpobj, 1, clen); return tmpobj; } /** * Use LinkedHashMap to preserve order of bundle entries. */ - protected Map createMap(int size) { - return new LinkedHashMap(size); + @Override + protected Map createMap(int size) { + return new LinkedHashMap<>(size); } /** -- GitLab