From 7e54878b26c0e6610701204ab3a5de8a82dd926a Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Wed, 29 Jun 2016 15:19:27 +0000 Subject: [PATCH] ICU-12456 Fixed compiler warnings. X-SVN-Rev: 38891 --- .../src/com/ibm/icu/impl/DayPeriodRules.java | 2 +- .../ibm/icu/text/BreakIteratorFactory.java | 8 ++- .../impl/ICUCurrencyDisplayInfoProvider.java | 6 +- .../dev/test/calendar/IBMCalendarTest.java | 47 +++++++++------- .../format/IntlTestDecimalFormatAPIC.java | 56 ++++++++++--------- 5 files changed, 68 insertions(+), 51 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/DayPeriodRules.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/DayPeriodRules.java index 6caf9b030fe..dc60c6059bd 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/DayPeriodRules.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/DayPeriodRules.java @@ -287,7 +287,7 @@ public final class DayPeriodRules { private static DayPeriodRulesData loadData() { DayPeriodRulesData data = new DayPeriodRulesData(); - ICUResourceBundle rb = (ICUResourceBundle)ICUResourceBundle.getBundleInstance( + ICUResourceBundle rb = ICUResourceBundle.getBundleInstance( ICUData.ICU_BASE_NAME, "dayPeriods", ICUResourceBundle.ICU_DATA_CLASS_LOADER, diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIteratorFactory.java b/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIteratorFactory.java index a7fafb02880..15339fc9c6a 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIteratorFactory.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIteratorFactory.java @@ -33,11 +33,13 @@ import com.ibm.icu.util.ULocale; */ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim { + @Override public Object registerInstance(BreakIterator iter, ULocale locale, int kind) { iter.setText(new java.text.StringCharacterIterator("")); return service.registerObject(iter, locale, kind); } + @Override public boolean unregister(Object key) { if (service.isDefault()) { return false; @@ -45,6 +47,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim return service.unregisterFactory((Factory)key); } + @Override public Locale[] getAvailableLocales() { if (service == null) { return ICUResourceBundle.getAvailableLocales(); @@ -53,6 +56,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim } } + @Override public ULocale[] getAvailableULocales() { if (service == null) { return ICUResourceBundle.getAvailableULocales(); @@ -61,6 +65,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim } } + @Override public BreakIterator createBreakIterator(ULocale locale, int kind) { // TODO: convert to ULocale when service switches over if (service.isDefault()) { @@ -77,6 +82,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim super("BreakIterator"); class RBBreakIteratorFactory extends ICUResourceBundleFactory { + @Override protected Object handleCreate(ULocale loc, int kind, ICUService srvc) { return createBreakInstance(loc, kind); } @@ -115,7 +121,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim private static BreakIterator createBreakInstance(ULocale locale, int kind) { RuleBasedBreakIterator iter = null; - ICUResourceBundle rb = (ICUResourceBundle)ICUResourceBundle. + ICUResourceBundle rb = ICUResourceBundle. getBundleInstance(ICUData.ICU_BRKITR_BASE_NAME, locale, ICUResourceBundle.OpenType.LOCALE_ROOT); diff --git a/icu4j/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyDisplayInfoProvider.java b/icu4j/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyDisplayInfoProvider.java index 5a5e1dfb5ab..cb374f6b83e 100644 --- a/icu4j/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyDisplayInfoProvider.java +++ b/icu4j/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyDisplayInfoProvider.java @@ -29,14 +29,15 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid public ICUCurrencyDisplayInfoProvider() { } + @Override public CurrencyDisplayInfo getInstance(ULocale locale, boolean withFallback) { ICUResourceBundle rb; if (withFallback) { - rb = (ICUResourceBundle) ICUResourceBundle.getBundleInstance( + rb = ICUResourceBundle.getBundleInstance( ICUData.ICU_CURR_BASE_NAME, locale, OpenType.LOCALE_DEFAULT_ROOT); } else { try { - rb = (ICUResourceBundle) ICUResourceBundle.getBundleInstance( + rb = ICUResourceBundle.getBundleInstance( ICUData.ICU_CURR_BASE_NAME, locale, OpenType.LOCALE_ONLY); } catch (MissingResourceException e) { return null; @@ -45,6 +46,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid return new ICUCurrencyDisplayInfo(rb, withFallback); } + @Override public boolean hasData() { return true; } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java index fcbc92d8d46..da3a6562c1a 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java @@ -333,7 +333,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { errln("FAIL: Buddhist calendar is not returned for locale " + cal.toString()); } } - + /** * Verify that TaiwanCalendar shifts years to Minguo Era but otherwise * behaves like GregorianCalendar. @@ -954,6 +954,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { */ private static final long serialVersionUID = -4558903444622684759L; + @Override protected int handleGetLimit(int field, int limitType) { if (limitType == Calendar.LEAST_MAXIMUM) { return 1; @@ -962,6 +963,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { } return -1; } + @Override protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) { if (useMonth) { return eyear * 365 + month * 31; @@ -969,6 +971,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { return eyear * 365; } } + @Override protected int handleGetExtendedYear() {return 2017;} public void run(){ @@ -990,18 +993,18 @@ public class IBMCalendarTest extends CalendarTestFmwk { // Tests for complete coverage of Calendar functions. int julianDay = Calendar.millisToJulianDay(millis - 1); assertEquals("Julian max day -1", julianDay, Calendar.MAX_JULIAN - 1); - + DateFormat df1 = handleGetDateFormat("GG yyyy-d:MM", "option=xyz", Locale.getDefault()); if (!df1.equals(handleGetDateFormat("GG yyyy-d:MM", "option=xyz", ULocale.getDefault()))){ - errln ("Calendar.handleGetDateFormat(String, Locale) should delegate to ( ,ULocale)"); + errln ("Calendar.handleGetDateFormat(String, Locale) should delegate to ( ,ULocale)"); } - + // Prove that the local overrides are used. int leastMsInDay = handleGetLimit(Calendar.MILLISECONDS_IN_DAY, Calendar.LEAST_MAXIMUM); assertEquals("getLimit test 1", leastMsInDay, 1); int maxMsInDay = handleGetLimit(Calendar.WEEK_OF_MONTH, Calendar.GREATEST_MINIMUM); assertEquals("getLimit test 2", 7, maxMsInDay); - + int febLeapLength = handleGetMonthLength(2020, Calendar.FEBRUARY); assertEquals("handleMonthLength", 31, febLeapLength); int exYear = handleGetExtendedYear(); @@ -1029,14 +1032,14 @@ public class IBMCalendarTest extends CalendarTestFmwk { ULocale loc = new ULocale("en_US"); // !!! Shouldn't we have an api like this? - // !!! Question: should this reflect those actually available in this copy of ICU, or + // !!! Question: should this reflect those actually available in this copy of ICU, or // the list of types we assume is available? // String[] calTypes = Calendar.getAvailableTypes(); final String[] calTypes = { - "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew", + "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew", "islamic", "islamic-civil", "japanese", "roc" }; - + // constructing a DateFormat with a locale indicating a calendar type should construct a // date format appropriate to that calendar final Date time = new Date(); @@ -1059,14 +1062,14 @@ public class IBMCalendarTest extends CalendarTestFmwk { // dateFormat.setCalendar should throw exception if wrong format for calendar if (false) { - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, - DateFormat.FULL, + DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, + DateFormat.FULL, new ULocale("en_US@calendar=chinese")); logln("dateformat type: " + df.getClass().getName()); Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=chinese")); - + logln("calendar type: " + cal.getClass().getName()); } } @@ -1199,10 +1202,12 @@ public class IBMCalendarTest extends CalendarTestFmwk { cal.set(Calendar.MILLISECOND, ms); } + @Override public String toString() { return String.format("%04d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, min, sec, ms); } + @Override public boolean equals(Object other) { if (other instanceof CalFields) { CalFields otr = (CalFields)other; @@ -1216,7 +1221,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { } return false; } - + boolean isEquivalentTo(Calendar cal) { return year == cal.get(Calendar.YEAR) && month == cal.get(Calendar.MONTH) + 1 @@ -1602,7 +1607,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { String calType = ucalTest.getType(); boolean era0YearsGoBackwards = (calType.equals("gregorian") || calType.equals("roc") || calType.equals("coptic")); int yrBefore, yrAfter, yrMax, eraAfter, eraMax, eraNow; - + ucalTest.clear(); ucalTest.set(Calendar.YEAR, 2); ucalTest.set(Calendar.ERA, 0); @@ -1670,7 +1675,7 @@ public class IBMCalendarTest extends CalendarTestFmwk { if ( yrAfter 1, try the same roll tests for current era ucalTest.setTime(new Date()); eraNow = ucalTest.get(Calendar.ERA); @@ -1957,14 +1962,16 @@ public class IBMCalendarTest extends CalendarTestFmwk { } } } - + public void TestSimpleDateFormatCoverage() { class StubSimpleDateFormat extends SimpleDateFormat { + private static final long serialVersionUID = 1L; + public StubSimpleDateFormat(String pattern, Locale loc) { new SimpleDateFormat(pattern, loc); } - + public void run(){ Calendar cal = Calendar.getInstance(Locale.US); cal.clear(); @@ -1973,17 +1980,17 @@ public class IBMCalendarTest extends CalendarTestFmwk { DateFormatSymbols theseSymbols = this.getSymbols(); String shouldBeMonday = theseSymbols.getWeekdays()[Calendar.MONDAY]; assertEquals("Should be Monday", "Monday", shouldBeMonday); - + String [] matchData = {"16", "2016", "2016AD", "Monday", "lunes"}; int matchIndex = matchString("Monday March 28, 2016", 0, Calendar.DAY_OF_WEEK, matchData, cal); assertEquals("matchData for Monday", 6, matchIndex); // Position of the pointer after the matched string. matchIndex = matchString("Monday March 28, 2016 AD", 17, Calendar.YEAR, matchData, cal); assertEquals("matchData for 2016", 21, matchIndex); // Position of the pointer after the matched string. - + char ch = 'y'; int count = 4; int beginOffset = 0; - cal.set(Calendar.YEAR, 2000); // Reset this + cal.set(Calendar.YEAR, 2000); // Reset this assertEquals("calendar year reset", 2000, cal.get(Calendar.YEAR)); FieldPosition pos = new FieldPosition(java.text.DateFormat.YEAR_FIELD); String subFormatResult = subFormat(ch, count, beginOffset, diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPIC.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPIC.java index 5353f86e5bb..5a8a5448f80 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPIC.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPIC.java @@ -7,7 +7,7 @@ ******************************************************************************* */ -/** +/** * Port From: ICU4C v1.8.1 : format : IntlTestDecimalFormatAPI * Source File: $ICU4CRoot/source/test/intltest/dcfmapts.cpp **/ @@ -35,7 +35,7 @@ import com.ibm.icu.util.ULocale; // try to test the full functionality. It just calls each function in the class and // verifies that it works on a basic level. public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { - + // This test checks various generic API methods in DecimalFormat to achieve 100% API coverage. @Test public void TestAPI() { @@ -53,7 +53,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { final String pattern = new String("#,##0.# FF"); final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRENCH); final CurrencyPluralInfo infoInput = new CurrencyPluralInfo(ULocale.FRENCH); - + DecimalFormat pat = null; try { pat = new DecimalFormat(pattern); @@ -67,7 +67,8 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { } catch (IllegalArgumentException e) { errln("ERROR: Could not create DecimalFormat (pattern, symbols)"); } - + + @SuppressWarnings("unused") DecimalFormat cust2 = null; try { cust2 = new DecimalFormat(pattern, symbols, infoInput, NumberFormat.PLURALCURRENCYSTYLE); @@ -127,7 +128,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { double d2 = pat.parse(text, pos).doubleValue(); if (d2 != d) { errln( - "ERROR: Roundtrip failed (via parse(" + Double.toString(d2) + " != " + Double.toString(d) + ")) for " + text); + "ERROR: Roundtrip failed (via parse(" + Double.toString(d2) + " != " + Double.toString(d) + ")) for " + text); } logln(text + " parsed into " + (long) d2); @@ -192,7 +193,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { pat.setDecimalSeparatorAlwaysShown(true); boolean tf = pat.isDecimalSeparatorAlwaysShown(); logln( - "DecimalSeparatorIsAlwaysShown (should be true) is " + (tf ? "true" : "false")); + "DecimalSeparatorIsAlwaysShown (should be true) is " + (tf ? "true" : "false")); if (tf != true) { errln("ERROR: setDecimalSeparatorAlwaysShown() failed"); } @@ -204,13 +205,13 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { String locPat; locPat = pat.toLocalizedPattern(); logln("Localized pattern is " + locPat); - + pat.setCurrencyPluralInfo(infoInput); if(!infoInput.equals(pat.getCurrencyPluralInfo())) { errln("ERROR: set/get CurrencyPluralInfo() failed"); } - + pat.setCurrencyPluralInfo(infoInput); if(!infoInput.equals(pat.getCurrencyPluralInfo())) { errln("ERROR: set/get CurrencyPluralInfo() failed"); @@ -254,7 +255,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { // catch (Exception e) { // errln("ERROR: Couldn't create a DecimalFormat"); // } - + } @Test @@ -263,13 +264,13 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { double Roundingnumber1 = -2.55; //+2.55 results -2.55 results double result[] = { - 3, -3, - 2, -2, - 3, -2, - 2, -3, - 3, -3, - 3, -3, - 3, -3 + 3, -3, + 2, -2, + 3, -2, + 2, -3, + 3, -3, + 3, -3, + 3, -3 }; DecimalFormat pat = new DecimalFormat(); String s = ""; @@ -283,22 +284,22 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { pat.setRoundingMode(mode); if (pat.getRoundingMode() != mode) { errln( - "SetRoundingMode or GetRoundingMode failed for mode=" + mode); + "SetRoundingMode or GetRoundingMode failed for mode=" + mode); } //for +2.55 with RoundingIncrement=1.0 pat.setRoundingIncrement(1.0); resultStr = pat.format(Roundingnumber); - message = "round(" + (double) Roundingnumber - + "," + mode + ",FALSE) with RoundingIncrement=1.0==>"; + message = "round(" + Roundingnumber + + "," + mode + ",FALSE) with RoundingIncrement=1.0==>"; verify(message, resultStr, result[i++]); message = ""; resultStr = ""; //for -2.55 with RoundingIncrement=1.0 resultStr = pat.format(Roundingnumber1); - message = "round(" + (double) Roundingnumber1 - + "," + mode + ",FALSE) with RoundingIncrement=1.0==>"; + message = "round(" + Roundingnumber1 + + "," + mode + ",FALSE) with RoundingIncrement=1.0==>"; verify(message, resultStr, result[i++]); message = ""; resultStr = ""; @@ -359,7 +360,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION)); return v; } - + // private static Vector getPositiveCurrencyVectorTR() { // Vector v = new Vector(); // v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER)); @@ -449,8 +450,8 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { List v = new ArrayList(1); v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER)); return v; - } - + } + private void t_Format(int count, Object object, Format format, List expectedResults) { List results = findFields(format.formatToCharacterIterator(object)); @@ -465,11 +466,11 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { private static boolean compare(List vector1, List vector2) { return vector1.size() == vector2.size() && vector1.containsAll(vector2); } - + /** * finds attributes with regards to char index in this * AttributedCharacterIterator, and puts them in a vector - * + * * @param iterator * @return a vector, each entry in this vector are of type FieldContainer , * which stores start and end indexes and an attribute this range @@ -523,6 +524,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { this.value = value; } + @Override public boolean equals(Object obj) { if (!(obj instanceof FieldContainer)) return false; @@ -531,7 +533,7 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk { return (start == fc.start && end == fc.end && attribute == fc.attribute && value.equals(fc.value)); } - } + } /*Helper functions */ public void verify(String message, String got, double expected) {