From 4ff5d6a0703f733eb34b329a443e221858c230bb Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Sat, 14 Dec 2024 08:32:19 +0000 Subject: [PATCH] ICU-22920 Fix raw type warnings in icu4j core tests --- .../java/com/ibm/icu/dev/test/ModuleTest.java | 2 +- .../com/ibm/icu/dev/test/ResourceModule.java | 33 ++++--- .../com/ibm/icu/dev/test/TestBoilerplate.java | 29 +++--- .../com/ibm/icu/dev/test/TestDataModule.java | 6 +- .../dev/test/UnicodeMapBoilerplateTest.java | 8 +- .../com/ibm/icu/dev/test/UnicodeMapTest.java | 98 +++++++++---------- .../test/calendar/CalendarRegressionTest.java | 2 +- .../dev/test/calendar/CalendarTestFmwk.java | 10 +- .../dev/test/duration/LanguageTestFmwk.java | 13 ++- ...ceBasedPeriodFormatterDataServiceTest.java | 7 +- .../test/format/DateTimeGeneratorTest.java | 9 +- .../dev/test/format/ListFormatterTest.java | 2 +- .../test/format/MessageRegressionTest.java | 32 +++--- .../dev/test/format/PluralFormatUnitTest.java | 4 +- .../dev/test/lang/DataDrivenUScriptTest.java | 12 +-- .../test/lang/UCharacterSurrogateTest.java | 6 +- .../ibm/icu/dev/test/lang/UCharacterTest.java | 2 +- .../dev/test/lang/UCharacterThreadTest.java | 9 +- .../ibm/icu/dev/test/lang/UnicodeSetTest.java | 62 ++++++------ .../normalizer/TestCanonicalIterator.java | 16 ++- .../com/ibm/icu/dev/test/rbbi/RBBITest.java | 4 +- .../ibm/icu/dev/test/rbbi/RBBITestMonkey.java | 18 ++-- .../DataDrivenArabicShapingRegTest.java | 10 +- .../test/stringprep/IDNAConformanceTest.java | 21 ++-- .../test/stringprep/NamePrepTransform.java | 2 +- .../icu/dev/test/text/SpoofCheckerTest.java | 4 +- .../dev/test/timezone/TimeZoneAliasTest.java | 59 +++++------ .../icu/dev/test/timezone/TimeZoneTest.java | 2 +- .../icu/dev/test/util/DisplayNameTest.java | 33 +++---- .../dev/test/util/ICUServiceTestSample.java | 18 ++-- .../dev/test/util/ICUServiceThreadTest.java | 44 ++++----- .../com/ibm/icu/dev/test/util/RegionTest.java | 3 +- .../icu/dev/test/util/TestLocaleValidity.java | 7 +- .../icu/dev/test/util/TextTrieMapTest.java | 10 +- .../ibm/icu/dev/test/util/UtilityTest.java | 4 +- 35 files changed, 282 insertions(+), 319 deletions(-) diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ModuleTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ModuleTest.java index a229fe49dd6e..b371b6aa61b5 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ModuleTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ModuleTest.java @@ -70,7 +70,7 @@ public static List getTestData(String moduleLocation, String modul Iterator tIter = m.getTestDataIterator(); while (tIter.hasNext()) { TestData t = tIter.next(); - for (Iterator siter = t.getSettingsIterator(); siter.hasNext();) { + for (Iterator siter = t.getSettingsIterator(); siter.hasNext();) { DataMap settings = (DataMap) siter.next(); list.add(new TestDataPair(t, settings)); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ResourceModule.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ResourceModule.java index 97dc7947803e..0ee8c4fb5a4f 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ResourceModule.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ResourceModule.java @@ -103,9 +103,9 @@ public TestData getTestData(String testName) throws DataModuleFormatError { return new UResourceTestData(defaultHeader, testData.get(testName)); } - public Iterator getTestDataIterator() { - return new IteratorAdapter(testData){ - protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError { + public Iterator getTestDataIterator() { + return new IteratorAdapter(testData){ + protected TestData prepareNext(UResourceBundle nextRes) throws DataModuleFormatError { return new UResourceTestData(defaultHeader, nextRes); } }; @@ -116,11 +116,12 @@ protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatErr * and return various data-driven test object for next() call * * @author Raymond Yang + * @param */ - private abstract static class IteratorAdapter implements Iterator{ + private abstract static class IteratorAdapter implements Iterator{ private UResourceBundle res; private UResourceBundleIterator itr; - private Object preparedNextElement = null; + private T preparedNextElement = null; // fix a strange behavior for UResourceBundleIterator for // UResourceBundle.STRING. It support hasNext(), but does // not support next() now. @@ -178,9 +179,9 @@ public boolean hasNext() { } } - public Object next(){ + public T next(){ if (hasNext()) { - Object t = preparedNextElement; + T t = preparedNextElement; preparedNextElement = null; return t; } else { @@ -190,7 +191,7 @@ public Object next(){ /** * To prepare data-driven test object for next() call, should not return null */ - abstract protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError; + abstract protected T prepareNext(UResourceBundle nextRes) throws DataModuleFormatError; } @@ -327,21 +328,21 @@ public DataMap getInfo() { return info == null ? null : new UTableResource(info); } - public Iterator getSettingsIterator() { + public Iterator getSettingsIterator() { assert_is (settings.getType() == UResourceBundle.ARRAY); - return new IteratorAdapter(settings){ - protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError { + return new IteratorAdapter(settings){ + protected DataMap prepareNext(UResourceBundle nextRes) throws DataModuleFormatError { return new UTableResource(nextRes); } }; } - public Iterator getDataIterator() { + public Iterator getDataIterator() { // unfortunately, assert_is (data.getType() == UResourceBundle.ARRAY || data.getType() == UResourceBundle.STRING); - return new IteratorAdapter(data){ - protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError { + return new IteratorAdapter(data){ + protected DataMap prepareNext(UResourceBundle nextRes) throws DataModuleFormatError { return new UArrayResource(header, nextRes); } }; @@ -370,7 +371,7 @@ public Object getObject(String key) { } private static class UArrayResource implements DataMap{ - private Map theMap; + private Map theMap; UArrayResource(UResourceBundle theHeader, UResourceBundle theData) throws DataModuleFormatError{ assert_is (theHeader != null && theData != null); String[] header; @@ -378,7 +379,7 @@ private static class UArrayResource implements DataMap{ header = getStringArrayHelper(theHeader); if (theData.getSize() != header.length) throw new DataModuleFormatError("The count of Header and Data is mismatch."); - theMap = new HashMap(); + theMap = new HashMap<>(); for (int i = 0; i < header.length; i++) { if(theData.getType()==UResourceBundle.ARRAY){ theMap.put(header[i], theData.get(i)); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestBoilerplate.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestBoilerplate.java index 730c9f3d938f..c809f4f4d121 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestBoilerplate.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestBoilerplate.java @@ -129,12 +129,12 @@ protected boolean _canClone(T a) { * @return clone */ protected T _clone(T a) throws Exception { - Class aClass = a.getClass(); + Class aClass = a.getClass(); try { Method cloner = aClass.getMethod("clone", (Class[])null); return (T) cloner.invoke(a,(Object[])null); } catch (NoSuchMethodException e) { - Constructor constructor = aClass.getConstructor(new Class[] {aClass}); + Constructor constructor = aClass.getConstructor(new Class[] {aClass}); return (T) constructor.newInstance(new Object[]{a}); } } @@ -150,26 +150,25 @@ public static boolean verifySetsIdentical(AbstractTestLog here, UnicodeSet set1, return false; } - public static boolean verifySetsIdentical(AbstractTestLog here, Set values1, Set values2) { + public static boolean verifySetsIdentical(AbstractTestLog here, Set values1, Set values2) { if (values1.equals(values2)) return true; - Set temp; + Set temp; TestFmwk.errln("Values differ:"); TestFmwk.errln("UnicodeMap - HashMap"); - temp = new TreeSet(values1); + temp = new TreeSet<>(values1); temp.removeAll(values2); TestFmwk.errln(show(temp)); TestFmwk.errln("HashMap - UnicodeMap"); - temp = new TreeSet(values2); + temp = new TreeSet<>(values2); temp.removeAll(values1); TestFmwk.errln(show(temp)); return false; } - - public static String show(Map m) { + + public static String show(Map m) { StringBuilder buffer = new StringBuilder(); - for (Iterator it = m.keySet().iterator(); it.hasNext();) { - Object key = it.next(); - buffer.append(key + "=>" + m.get(key) + "\r\n"); + for (Map.Entry e : m.entrySet()) { + buffer.append(e.getKey() + "=>" + e.getValue() + "\r\n"); } return buffer.toString(); } @@ -184,11 +183,11 @@ public static UnicodeSet getSet(Map m, T value) { } return result; } - - public static String show(Collection c) { + + public static String show(Collection c) { StringBuilder buffer = new StringBuilder(); - for (Iterator it = c.iterator(); it.hasNext();) { - buffer.append(it.next() + "\r\n"); + for (T item : c) { + buffer.append(item + "\r\n"); } return buffer.toString(); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestDataModule.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestDataModule.java index 1e2ca94efdf7..997375ba8189 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestDataModule.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestDataModule.java @@ -36,7 +36,7 @@ public interface TestDataModule { /** * @return Iterator */ - public Iterator getTestDataIterator(); + public Iterator getTestDataIterator(); public static class Factory{ @@ -74,11 +74,11 @@ public static interface TestData { /** * @return Iterator */ - public Iterator getSettingsIterator(); + public Iterator getSettingsIterator(); /** * @return Iterator */ - public Iterator getDataIterator(); + public Iterator getDataIterator(); } /** diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapBoilerplateTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapBoilerplateTest.java index 8118a3c2fbfa..7c540f1ba190 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapBoilerplateTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapBoilerplateTest.java @@ -17,7 +17,7 @@ /** * Moved from UnicodeMapTest */ -public class UnicodeMapBoilerplateTest extends TestBoilerplate { +public class UnicodeMapBoilerplateTest extends TestBoilerplate> { private static String[] TEST_VALUES = {"A", "B", "C", "D", "E", "F"}; @@ -32,7 +32,7 @@ public void test() throws Exception { /* (non-Javadoc) * @see com.ibm.icu.dev.test.TestBoilerplate#_hasSameBehavior(java.lang.Object, java.lang.Object) */ - protected boolean _hasSameBehavior(UnicodeMap a, UnicodeMap b) { + protected boolean _hasSameBehavior(UnicodeMap a, UnicodeMap b) { // we are pretty confident in the equals method, so won't bother with this right now. return true; } @@ -40,9 +40,9 @@ protected boolean _hasSameBehavior(UnicodeMap a, UnicodeMap b) { /* (non-Javadoc) * @see com.ibm.icu.dev.test.TestBoilerplate#_addTestObject(java.util.List) */ - protected boolean _addTestObject(List list) { + protected boolean _addTestObject(List> list) { if (list.size() > 30) return false; - UnicodeMap result = new UnicodeMap(); + UnicodeMap result = new UnicodeMap<>(); for (int i = 0; i < 50; ++i) { int start = random.nextInt(25); String value = TEST_VALUES[random.nextInt(TEST_VALUES.length)]; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapTest.java index b1144aed93b3..400380d433fe 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapTest.java @@ -13,7 +13,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Random; import java.util.Set; import java.util.SortedMap; @@ -46,7 +45,7 @@ public class UnicodeMapTest extends TestFmwk { @Test public void TestIterations() { - UnicodeMap foo = new UnicodeMap(); + UnicodeMap foo = new UnicodeMap<>(); checkToString(foo, ""); foo.put(3, 6d).put(5, 10d); checkToString(foo, "0003=6.0\n0005=10.0\n"); @@ -64,7 +63,7 @@ public void TestIterations() { public void checkToString(UnicodeMap foo, String expected) { StringJoiner joiner = new StringJoiner("\n"); - for (UnicodeMap.EntryRange range : foo.entryRanges()) { + for (UnicodeMap.EntryRange range : foo.entryRanges()) { joiner.add(range.toString()); } assertEquals("EntryRange", expected, joiner.toString() + (foo.size() == 0 ? "" : "\n")); @@ -73,30 +72,30 @@ public void checkToString(UnicodeMap foo, String expected) { @Test public void TestRemove() { - UnicodeMap foo = new UnicodeMap() - .putAll(0x20, 0x29, -2d) - .put("abc", 3d) - .put("xy", 2d) - .put("mark", 4d) - .freeze(); - UnicodeMap fii = new UnicodeMap() - .putAll(0x21, 0x25, -2d) - .putAll(0x26, 0x28, -3d) - .put("abc", 3d) - .put("mark", 999d) - .freeze(); - - UnicodeMap afterFiiRemoval = new UnicodeMap() - .put(0x20, -2d) - .putAll(0x26, 0x29, -2d) - .put("xy", 2d) - .put("mark", 4d) - .freeze(); - - UnicodeMap afterFiiRetained = new UnicodeMap() - .putAll(0x21, 0x25, -2d) - .put("abc", 3d) - .freeze(); + UnicodeMap foo = new UnicodeMap() + .putAll(0x20, 0x29, -2d) + .put("abc", 3d) + .put("xy", 2d) + .put("mark", 4d) + .freeze(); + UnicodeMap fii = new UnicodeMap() + .putAll(0x21, 0x25, -2d) + .putAll(0x26, 0x28, -3d) + .put("abc", 3d) + .put("mark", 999d) + .freeze(); + + UnicodeMap afterFiiRemoval = new UnicodeMap() + .put(0x20, -2d) + .putAll(0x26, 0x29, -2d) + .put("xy", 2d) + .put("mark", 4d) + .freeze(); + + UnicodeMap afterFiiRetained = new UnicodeMap() + .putAll(0x21, 0x25, -2d) + .put("abc", 3d) + .freeze(); UnicodeMap test = new UnicodeMap().putAll(foo) .removeAll(fii); @@ -117,7 +116,7 @@ public void TestAMonkey() { me.remove(0x10FFFF); int iterations = 100000; - SortedMap test = new TreeMap(); + SortedMap test = new TreeMap<>(); Random rand = new Random(0); String other; @@ -178,17 +177,16 @@ private SortedMap fillRandomMap(Random rand, int max, SortedMap return test; } - Set temp = new HashSet(); /** * @param me * @param stayWithMe */ private void checkEquals(UnicodeMap me, SortedMap stayWithMe) { - temp.clear(); - for (Entry e : me.entrySet()) { + Set> temp = new HashSet<>(); + for (Map.Entry e : me.entrySet()) { temp.add(e); } - Set> entrySet = stayWithMe.entrySet(); + Set> entrySet = stayWithMe.entrySet(); if (!entrySet.equals(temp)) { logln(me.entrySet().toString()); logln(me.toString()); @@ -260,8 +258,8 @@ private String getRandomKey(Random rand) { @Test public void TestModify() { Random random = new Random(0); - UnicodeMap unicodeMap = new UnicodeMap(); - HashMap hashMap = new HashMap(); + UnicodeMap unicodeMap = new UnicodeMap<>(); + HashMap hashMap = new HashMap<>(); String[] values = {null, "the", "quick", "brown", "fox"}; for (int count = 1; count <= MODIFY_TEST_ITERATIONS; ++count) { String value = values[random.nextInt(values.length)]; @@ -291,10 +289,10 @@ public void TestModify() { } } - private boolean hasSameValues(UnicodeMap unicodeMap, HashMap hashMap) { + private boolean hasSameValues(UnicodeMap unicodeMap, HashMap hashMap) { for (int i = 0; i < MODIFY_TEST_LIMIT; ++i) { - Object unicodeMapValue = unicodeMap.getValue(i); - Object hashMapValue = hashMap.get(i); + String unicodeMapValue = unicodeMap.getValue(i); + String hashMapValue = hashMap.get(i); if (unicodeMapValue != hashMapValue) { return false; } @@ -304,7 +302,7 @@ private boolean hasSameValues(UnicodeMap unicodeMap, HashMap hashMap) { @Test public void TestCloneAsThawed11721 () { - UnicodeMap test = new UnicodeMap().put("abc", 3).freeze(); + UnicodeMap test = new UnicodeMap().put("abc", 3).freeze(); UnicodeMap copy = test.cloneAsThawed(); copy.put("def", 4); assertEquals("original-abc", (Integer) 3, test.get("abc")); @@ -326,7 +324,7 @@ public void TestUnicodeMapRandom() { // do random change to both, then compare random.setSeed(12345); // reproducible results logln("Comparing against HashMap"); - UnicodeMap map1 = new UnicodeMap(); + UnicodeMap map1 = new UnicodeMap<>(); Map map2 = new HashMap(); for (int counter = 0; counter < ITERATIONS; ++counter) { int start = random.nextInt(LIMIT); @@ -349,7 +347,7 @@ public void TestUnicodeMapRandom() { @Test public void TestUnicodeMapGeneralCategory() { logln("Setting General Category"); - UnicodeMap map1 = new UnicodeMap(); + UnicodeMap map1 = new UnicodeMap<>(); Map map2 = new HashMap(); //Map map3 = new TreeMap(); map1 = new UnicodeMap(); @@ -396,11 +394,11 @@ public void TestUnicodeMapGeneralCategory() { @Test public void TestAUnicodeMap2() { - UnicodeMap foo = new UnicodeMap(); + UnicodeMap foo = new UnicodeMap<>(); @SuppressWarnings("unused") int hash = foo.hashCode(); // make sure doesn't NPE @SuppressWarnings("unused") - Set fii = foo.stringKeys(); // make sure doesn't NPE + Set fii = foo.stringKeys(); // make sure doesn't NPE } @Test @@ -413,13 +411,13 @@ public void TestAUnicodeMapInverse() { ; Map target = new HashMap(); foo1.addInverseTo(target); - UnicodeMap reverse = new UnicodeMap().putAllInverse(target); + UnicodeMap reverse = new UnicodeMap().putAllInverse(target); assertEquals("", foo1, reverse); } private void checkNext(UnicodeMap map1, Map map2, int limit) { logln("Comparing nextRange"); - Map localMap = new TreeMap(); + Map localMap = new TreeMap<>(); UnicodeMapIterator mi = new UnicodeMapIterator(map1); while (mi.nextRange()) { logln(Utility.hex(mi.codepoint) + ".." + Utility.hex(mi.codepointEnd) + " => " + mi.value); @@ -432,7 +430,7 @@ private void checkNext(UnicodeMap map1, Map map2, int li logln("Comparing next"); mi.reset(); - localMap = new TreeMap(); + localMap = new TreeMap<>(); // String lastValue = null; while (mi.next()) { // if (!UnicodeMap.areEqual(lastValue, mi.value)) { @@ -460,11 +458,11 @@ public void check(UnicodeMap map1, Map map2, int counter } } - void checkMap(Map m1, Map m2) { + void checkMap(Map m1, Map m2) { if (m1.equals(m2)) return; StringBuilder buffer = new StringBuilder(); - Set m1entries = m1.entrySet(); - Set m2entries = m2.entrySet(); + Set> m1entries = m1.entrySet(); + Set> m2entries = m2.entrySet(); getEntries("\r\nIn First, and not Second", m1entries, m2entries, buffer, 20); getEntries("\r\nIn Second, and not First", m2entries, m1entries, buffer, 20); errln(buffer.toString()); @@ -482,7 +480,7 @@ public int compare(Map.Entry o1, Map.Entry o2) if (result != 0) return result; return compare2(a.getValue(), b.getValue()); } - private int compare2(T o1, T o2) { + private > int compare2(T o1, T o2) { if (o1 == o2) return 0; if (o1 == null) return -1; if (o2 == null) return 1; @@ -495,7 +493,7 @@ private void getEntries(String title, Set> m1entries, m1_m2.addAll(m1entries); m1_m2.removeAll(m2entries); buffer.append(title + ": " + m1_m2.size() + "\r\n"); - for (Entry entry : m1_m2) { + for (Map.Entry entry : m1_m2) { if (limit-- < 0) return; buffer.append(entry.getKey()).append(" => ") .append(entry.getValue()).append("\r\n"); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarRegressionTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarRegressionTest.java index 746b5b08bd35..5e247ad8050f 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarRegressionTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarRegressionTest.java @@ -2193,7 +2193,7 @@ public void TestGetKeywordValuesForLocale(){ }; String[] ALL = Calendar.getKeywordValuesForLocale("calendar", ULocale.getDefault(), false); - HashSet ALLSET = new HashSet(); + HashSet ALLSET = new HashSet<>(); for (int i = 0; i < ALL.length; i++) { if (ALL[i] == "unknown") { errln("Calendar.getKeywordValuesForLocale should not return \"unknown\""); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarTestFmwk.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarTestFmwk.java index fc9f33eed39c..f04ce436720e 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarTestFmwk.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/calendar/CalendarTestFmwk.java @@ -241,7 +241,7 @@ protected void doLimitsTest(Calendar cal, int[] fieldsToTest, // Keep a record of minima and maxima that we actually see. // These are kept in an array of arrays of hashes. - Map[][] limits = new Map[fieldsToTest.length][2]; + Map[][] limits = new Map[fieldsToTest.length][2]; Object nub = new Object(); // Meaningless placeholder // This test can run for a long time; show progress. @@ -273,10 +273,10 @@ protected void doLimitsTest(Calendar cal, int[] fieldsToTest, // Fetch the hash for this field and keep track of the // minima and maxima. - Map[] h = limits[j]; + Map[] h = limits[j]; if (h[0] == null) { - h[0] = new HashMap(); - h[1] = new HashMap(); + h[0] = new HashMap<>(); + h[1] = new HashMap<>(); } h[0].put(minActual, nub); h[1].put(maxActual, nub); @@ -311,7 +311,7 @@ protected void doLimitsTest(Calendar cal, int[] fieldsToTest, int f = fieldsToTest[j]; buf.setLength(0); buf.append(FIELD_NAME[f]); - Map[] h = limits[j]; + Map[] h = limits[j]; boolean fullRangeSeen = true; for (int k=0; k<2; ++k) { int rangeLow = (k==0) ? diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/LanguageTestFmwk.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/LanguageTestFmwk.java index e7dbb058f610..13f7484114d6 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/LanguageTestFmwk.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/LanguageTestFmwk.java @@ -63,7 +63,7 @@ protected boolean inheritTargets() { private PrintWriter pw; - private static final Map datacache = new HashMap(); // String->TestData + private static final Map datacache = new HashMap<>(); // String->TestData private static final long[] approxDurations = { 36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L, @@ -79,7 +79,7 @@ private static TestData getTestData(String locale) { if (locale.equals("testFullPluralizedForms")) { Thread.dumpStack(); } - TestData data = (TestData) datacache.get(locale); + TestData data = datacache.get(locale); if (data == null) { try { InputStream is = LanguageTestFmwk.class @@ -604,14 +604,13 @@ class Wrapup { String[] stringArray; - void wrapup(List /* of String */list, Element element) { + void wrapup(List list, Element element) { if (list == null) return; switch (element.mode) { case EMode.mString: - stringArray = (String[]) list.toArray(new String[list - .size()]); + stringArray = list.toArray(new String[list.size()]); break; case EMode.mInt: @@ -668,7 +667,7 @@ void wrapup(List /* of String */list, Element element) { } Wrapup w = new Wrapup(); - List /* of String */list = null; + List list = null; Element element = null; String line = null; while (null != (line = br.readLine())) { @@ -678,7 +677,7 @@ void wrapup(List /* of String */list, Element element) { if (line.charAt(0) == '=') { w.wrapup(list, element); - list = new ArrayList(); + list = new ArrayList<>(); element = Element.forString(line.substring(1)); } else if (line.equals("null")) { list.add(null); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/ResourceBasedPeriodFormatterDataServiceTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/ResourceBasedPeriodFormatterDataServiceTest.java index 17af5f8214e7..ea94b7b63130 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/ResourceBasedPeriodFormatterDataServiceTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/duration/ResourceBasedPeriodFormatterDataServiceTest.java @@ -11,9 +11,6 @@ package com.ibm.icu.dev.test.duration; -import java.util.Collection; -import java.util.Iterator; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -28,9 +25,7 @@ public class ResourceBasedPeriodFormatterDataServiceTest extends CoreTestFmwk { public void testAvailable() { ResourceBasedPeriodFormatterDataService service = ResourceBasedPeriodFormatterDataService.getInstance(); - Collection locales = service.getAvailableLocales(); - for (Iterator i = locales.iterator(); i.hasNext();) { - String locale = (String)i.next(); + for (String locale : service.getAvailableLocales()) { PeriodFormatterData pfd = service.get(locale); assertFalse(locale + ": " + pfd.pluralization(), -1 == pfd.pluralization()); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java index 2a34123a4fec..25de60c10a85 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java @@ -13,7 +13,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -777,7 +776,7 @@ public boolean equals(Object that) { * @return */ public String replaceZoneString(String pattern, String newZone) { - final List itemList = formatParser.set(pattern).getItems(); + final List itemList = formatParser.set(pattern).getItems(); boolean changed = false; for (int i = 0; i < itemList.size(); ++i) { Object item = itemList.get(i); @@ -795,8 +794,7 @@ public String replaceZoneString(String pattern, String newZone) { } public boolean containsZone(String pattern) { - for (Iterator it = formatParser.set(pattern).getItems().iterator(); it.hasNext();) { - Object item = it.next(); + for (Object item : formatParser.set(pattern).getItems()) { if (item instanceof VariableField) { VariableField variableField = (VariableField) item; if (variableField.getType() == DateTimePatternGenerator.ZONE) { @@ -829,8 +827,7 @@ private DateOrder getOrdering(int style, ULocale locale) { int count = 0; DateOrder result = new DateOrder(); - for (Iterator it = formatParser.set(pattern).getItems().iterator(); it.hasNext();) { - Object item = it.next(); + for (Object item : formatParser.set(pattern).getItems()) { if (!(item instanceof String)) { // the first character of the variable field determines the type, // according to CLDR. diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/ListFormatterTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/ListFormatterTest.java index feb47927100e..debc63b0c4b7 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/ListFormatterTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/ListFormatterTest.java @@ -418,7 +418,7 @@ public void TestContextual() { String expected = (String) cas[2]; for (String locale : locales) { ULocale uloc = new ULocale(locale); - List inputs = Arrays.asList(cas).subList(3, cas.length); + List inputs = Arrays.asList(cas).subList(3, cas.length); ListFormatter fmt = ListFormatter.getInstance(uloc, type, width); String message = "TestContextual uloc=" + uloc + " type=" diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/MessageRegressionTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/MessageRegressionTest.java index 71638854c14b..e38df34f4498 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/MessageRegressionTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/MessageRegressionTest.java @@ -677,19 +677,17 @@ public void testBugTestsWithNamesArguments() { try { logln("Apply with pattern : " + pattern1); messageFormatter.applyPattern(pattern1); - HashMap paramsMap = new HashMap(); + HashMap paramsMap = new HashMap<>(); paramsMap.put("arg0", 7); String tempBuffer = messageFormatter.format(paramsMap); if (!tempBuffer.equals("Impossible {arg1} has occurred -- status code is 7 and message is {arg2}.")) errln("Tests arguments < substitution failed"); logln("Formatted with 7 : " + tempBuffer); ParsePosition status = new ParsePosition(0); - Map objs = messageFormatter.parseToMap(tempBuffer, status); + Map objs = messageFormatter.parseToMap(tempBuffer, status); if (objs.get("arg1") != null || objs.get("arg2") != null) errln("Parse failed with more than expected arguments"); - for (Iterator keyIter = objs.keySet().iterator(); - keyIter.hasNext();) { - String key = (String) keyIter.next(); + for (String key : objs.keySet()) { if (objs.get(key) != null && !objs.get(key).toString().equals(paramsMap.get(key).toString())) { errln("Parse failed on object " + objs.get(key) + " with argument name : " + key ); } @@ -721,7 +719,7 @@ public void testBugTestsWithNamesArguments() { } MessageFormat fmt = new MessageFormat("There are {numberOfApples} apples growing on the {whatKindOfTree} tree."); String str = new String("There is one apple growing on the peach tree."); - Map objs = fmt.parseToMap(str, pos); + Map objs = fmt.parseToMap(str, pos); logln("unparsable string , should fail at " + pos.getErrorIndex()); if (pos.getErrorIndex() == -1) errln("Bug 4052223 failed : parsing string " + str); @@ -773,14 +771,14 @@ public void testBugTestsWithNamesArguments() { String pattern = patterns[i]; mf.applyPattern(pattern); try { - Map objs = mf.parseToMap(null, new ParsePosition(0)); + Map objs = mf.parseToMap(null, new ParsePosition(0)); logln("pattern: \"" + pattern + "\""); log(" parsedObjects: "); if (objs != null) { log("{"); - for (Iterator keyIter = objs.keySet().iterator(); + for (Iterator keyIter = objs.keySet().iterator(); keyIter.hasNext();) { - String key = (String)keyIter.next(); + String key = keyIter.next(); if (objs.get(key) != null) { err("\"" + objs.get(key).toString() + "\""); } else { @@ -802,9 +800,9 @@ public void testBugTestsWithNamesArguments() { } }{ // Taken from Test4114739(). MessageFormat mf = new MessageFormat("<{arg}>"); - Map objs1 = null; - Map objs2 = new HashMap(); - Map objs3 = new HashMap(); + Map objs1 = null; + Map objs2 = new HashMap<>(); + Map objs3 = new HashMap<>(); objs3.put("arg", null); try { logln("pattern: \"" + mf.toPattern() + "\""); @@ -821,14 +819,14 @@ public void testBugTestsWithNamesArguments() { String argName = "something_stupid"; MessageFormat mf = new MessageFormat("{"+ argName + "}, {" + argName + "}, {" + argName + "}"); String forParsing = "x, y, z"; - Map objs = mf.parseToMap(forParsing, new ParsePosition(0)); + Map objs = mf.parseToMap(forParsing, new ParsePosition(0)); logln("pattern: \"" + mf.toPattern() + "\""); logln("text for parsing: \"" + forParsing + "\""); if (!objs.get(argName).toString().equals("z")) errln("argument0: \"" + objs.get(argName) + "\""); mf.setLocale(Locale.US); mf.applyPattern("{" + argName + ",number,#.##}, {" + argName + ",number,#.#}"); - Map oldobjs = new HashMap(); + Map oldobjs = new HashMap<>(); oldobjs.put(argName, 3.1415d); String result = mf.format( oldobjs ); logln("pattern: \"" + mf.toPattern() + "\""); @@ -836,7 +834,7 @@ public void testBugTestsWithNamesArguments() { // result now equals "3.14, 3.1" if (!result.equals("3.14, 3.1")) errln("result = " + result); - Map newobjs = mf.parseToMap(result, new ParsePosition(0)); + Map newobjs = mf.parseToMap(result, new ParsePosition(0)); // newobjs now equals {Double.valueOf(3.1)} if (((Number)newobjs.get(argName)).doubleValue() != 3.1) // was (Double) [alan] errln( "newobjs.get(argName) = " + newobjs.get(argName)); @@ -850,14 +848,14 @@ public void testBugTestsWithNamesArguments() { ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); form1.setFormat(1, fileform); form2.setFormat(0, fileform); - Map testArgs = new HashMap(); + Map testArgs = new HashMap<>(); testArgs.put("diskName", "MyDisk"); testArgs.put("numberOfFiles", 12373L); logln(form1.format(testArgs)); logln(form2.format(testArgs)); }{ // Taken from test4293229(). MessageFormat format = new MessageFormat("'''{'myNamedArgument}'' '''{myNamedArgument}'''"); - Map args = new HashMap(); + Map args = new HashMap<>(); String expected = "'{myNamedArgument}' '{myNamedArgument}'"; String result = format.format(args); if (!result.equals(expected)) { diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java index 89339fe959d7..7b8d87fbd2a5 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java @@ -215,11 +215,11 @@ public void TestApplyPatternAndFormat() { @Test public void TestSamples() { - Map> same = new LinkedHashMap(); + Map> same = new LinkedHashMap<>(); for (ULocale locale : PluralRules.getAvailableULocales()) { ULocale otherLocale = PluralRules.getFunctionalEquivalent(locale, null); Set others = same.get(otherLocale); - if (others == null) same.put(otherLocale, others = new LinkedHashSet()); + if (others == null) same.put(otherLocale, others = new LinkedHashSet<>()); others.add(locale); continue; } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/DataDrivenUScriptTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/DataDrivenUScriptTest.java index 00df24b6bedc..ce1e084b9ef9 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/DataDrivenUScriptTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/DataDrivenUScriptTest.java @@ -48,7 +48,7 @@ public LocaleGetCodeTest(ULocale testLocaleName, int expected) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { { new ULocale("en"), UScript.LATIN }, { new ULocale("en_US"), UScript.LATIN }, { new ULocale("sr"), UScript.CYRILLIC }, @@ -126,7 +126,7 @@ public TestMultipleUScript(String testLocaleName, int[] expected, Locale testLoc } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { { "ja", new int[] { UScript.KATAKANA, UScript.HIRAGANA, UScript.HAN }, Locale.JAPANESE }, { "ko_KR", new int[] { UScript.HANGUL, UScript.HAN }, Locale.KOREA }, @@ -175,7 +175,7 @@ public GetCodeTest(String testName, int expected) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { /* test locale */ { "en", UScript.LATIN }, @@ -269,7 +269,7 @@ public GetNameTest(int testCode, String expected) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { { UScript.CYRILLIC, "Cyrillic" }, { UScript.DESERET, "Deseret" }, @@ -302,7 +302,7 @@ public GetShortNameTest(int testCode, String expected) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { { UScript.HAN, "Hani" }, { UScript.HANGUL, "Hang" }, @@ -338,7 +338,7 @@ public GetScriptTest(int[] codepoint) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new int[][] { { 0x0000FF9D, UScript.KATAKANA }, { 0x0000FFBE, UScript.HANGUL }, diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterSurrogateTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterSurrogateTest.java index 9990c3870f76..75df58a3bcaa 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterSurrogateTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterSurrogateTest.java @@ -263,7 +263,7 @@ void test(String s, int start, int limit, int expected) { } } - void fail(String s, int start, int limit, Class exc) { + void fail(String s, int start, int limit, Class exc) { try { UCharacter.codePointCount(s, start, limit); errln("unexpected success " + str(s, start, limit)); @@ -350,7 +350,7 @@ void test(String s, int start, int count, int index, int offset, } void fail(char[] text, int start, int count, int index, int offset, - Class exc) { + Class exc) { try { UCharacter.offsetByCodePoints(text, start, count, index, offset); @@ -365,7 +365,7 @@ void fail(char[] text, int start, int count, int index, int offset, } } - void fail(String text, int index, int offset, Class exc) { + void fail(String text, int index, int offset, Class exc) { try { UCharacter.offsetByCodePoints(text, index, offset); errln("unexpected success " diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterTest.java index 1701b8f17a62..cd950653a617 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterTest.java @@ -2988,7 +2988,7 @@ public void TestCoverage() { @Test public void TestBlockData() { - Class ubc = UCharacter.UnicodeBlock.class; + Class ubc = UCharacter.UnicodeBlock.class; for (int b = 1; b < UCharacter.UnicodeBlock.COUNT; b += 1) { UCharacter.UnicodeBlock blk = UCharacter.UnicodeBlock.getInstance(b); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterThreadTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterThreadTest.java index 5873fb36e5b5..86a9a2dd836b 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterThreadTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UCharacterThreadTest.java @@ -8,9 +8,8 @@ */ package com.ibm.icu.dev.test.lang; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; -import java.util.ListIterator; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,7 +41,7 @@ public UCharacterThreadTest() // @Test public void TestUCharactersGetName() throws InterruptedException { - List threads = new LinkedList(); + List threads = new ArrayList<>(); for(int t=0; t<20; t++) { int codePoint = 47 + t; String correctName = UCharacter.getName(codePoint); @@ -50,9 +49,7 @@ public void TestUCharactersGetName() throws InterruptedException { thread.start(); threads.add(thread); } - ListIterator i = threads.listIterator(); - while (i.hasNext()) { - GetNameThread thread = (GetNameThread)i.next(); + for (GetNameThread thread : threads) { thread.join(); if (!thread.correctName.equals(thread.actualName)) { errln("FAIL, expected \"" + thread.correctName + "\", got \"" + thread.actualName + "\""); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UnicodeSetTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UnicodeSetTest.java index 5c77f3c64c83..2bd6a8c18615 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UnicodeSetTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/lang/UnicodeSetTest.java @@ -781,8 +781,8 @@ public void TestAPI() { // Ram also add a similar test to UtilityTest.java logln("Testing addAll(Collection) ... "); String[] array = {"a", "b", "c", "de"}; - List list = Arrays.asList(array); - Set aset = new HashSet(list); + List list = Arrays.asList(array); + Set aset = new HashSet<>(list); logln(" *** The source set's size is: " + aset.size()); set.clear(); @@ -794,16 +794,16 @@ public void TestAPI() { logln("OK: After addAll, the UnicodeSet size got " + set.size()); } - List list2 = new ArrayList(); + List list2 = new ArrayList<>(); set.addAllTo(list2); //verify the result log(" *** The elements are: "); String s = set.toPattern(true); logln(s); - Iterator myiter = list2.iterator(); + Iterator myiter = list2.iterator(); while(myiter.hasNext()) { - log(myiter.next().toString() + " "); + log(myiter.next() + " "); } logln(""); // a new line } @@ -859,8 +859,8 @@ public void TestSetRelation() { String[] choices = {"a", "b", "cd", "ef"}; int limit = 1 << choices.length; - SortedSet iset = new TreeSet(); - SortedSet jset = new TreeSet(); + SortedSet iset = new TreeSet<>(); + SortedSet jset = new TreeSet<>(); for (int i = 0; i < limit; ++i) { pick(i, choices, iset); @@ -882,8 +882,8 @@ public void TestSetSpeed() { public void SetSpeed2(int size) { - SortedSet iset = new TreeSet(); - SortedSet jset = new TreeSet(); + SortedSet iset = new TreeSet<>(); + SortedSet jset = new TreeSet<>(); for (int i = 0; i < size*2; i += 2) { // only even values iset.add(i); @@ -907,12 +907,12 @@ public void SetSpeed2(int size) { CheckSpeed(jset, iset, "when a, b are disjoint", iterations); } - void CheckSpeed(SortedSet iset, SortedSet jset, String message, int iterations) { + void CheckSpeed(SortedSet iset, SortedSet jset, String message, int iterations) { CheckSpeed2(iset, jset, message, iterations); CheckSpeed3(iset, jset, message, iterations); } - void CheckSpeed2(SortedSet iset, SortedSet jset, String message, int iterations) { + void CheckSpeed2(SortedSet iset, SortedSet jset, String message, int iterations) { boolean x; boolean y; @@ -939,7 +939,7 @@ void CheckSpeed2(SortedSet iset, SortedSet jset, String message, int iterations) + ", Utility: " + utime + ", u:j: " + nf.format(utime/jtime)); } - void CheckSpeed3(SortedSet iset, SortedSet jset, String message, int iterations) { + void CheckSpeed3(SortedSet iset, SortedSet jset, String message, int iterations) { boolean x; boolean y; @@ -967,7 +967,7 @@ void CheckSpeed3(SortedSet iset, SortedSet jset, String message, int iterations) + ", Utility: " + utime + ", u:j: " + nf.format(utime/jtime)); } - void pick(int bits, Object[] examples, SortedSet output) { + void pick(int bits, String[] examples, SortedSet output) { output.clear(); for (int k = 0; k < 32; ++k) { if (((1< A, int filter, Collection B) { + Collection ab = new TreeSet<>(A); ab.retainAll(B); if (ab.size() > 0 && (filter & SortedSetRelation.A_AND_B) == 0) return false; @@ -999,7 +999,7 @@ boolean dumbHasRelation(Collection A, int filter, Collection B) { return true; } - void checkSetRelation(SortedSet a, SortedSet b, String message) { + void checkSetRelation(SortedSet a, SortedSet b, String message) { for (int i = 0; i < 8; ++i) { boolean hasRelation = SortedSetRelation.hasRelation(a, i, b); @@ -1768,16 +1768,16 @@ public void TestGenerics() { set1.addAllTo(list1); assertEquals("iteration test", oldList, list1); - list1 = set1.addAllTo(new ArrayList()); + list1 = set1.addAllTo(new ArrayList<>()); assertEquals("addAllTo", oldList, list1); - ArrayList list2 = set2.addAllTo(new ArrayList()); - ArrayList list3 = set3.addAllTo(new ArrayList()); + ArrayList list2 = set2.addAllTo(new ArrayList<>()); + ArrayList list3 = set3.addAllTo(new ArrayList<>()); // put them into different order, to check that order doesn't matter - TreeSet sorted1 = set1.addAllTo(new TreeSet()); - TreeSet sorted2 = set2.addAllTo(new TreeSet()); - TreeSet sorted3 = set3.addAllTo(new TreeSet()); + TreeSet sorted1 = set1.addAllTo(new TreeSet<>()); + TreeSet sorted2 = set2.addAllTo(new TreeSet<>()); + TreeSet sorted3 = set3.addAllTo(new TreeSet<>()); //containsAll(Collection collection) assertTrue("containsAll", set1.containsAll(list1)); @@ -1837,7 +1837,7 @@ public void TestComparison() { List goalLongest = Arrays.asList(set1, set3, set2); List goalLex = Arrays.asList(set1, set2, set3); - List sorted = new ArrayList(new TreeSet<>(unsorted)); + List sorted = new ArrayList<>(new TreeSet<>(unsorted)); assertNotEquals("compareTo-shorter-first", unsorted, sorted); assertEquals("compareTo-shorter-first", goalShortest, sorted); @@ -1848,7 +1848,7 @@ public int compare(UnicodeSet o1, UnicodeSet o2) { return o1.compareTo(o2, ComparisonStyle.LONGER_FIRST); }}); sorted1.addAll(unsorted); - sorted = new ArrayList(sorted1); + sorted = new ArrayList<>(sorted1); assertNotEquals("compareTo-longer-first", unsorted, sorted); assertEquals("compareTo-longer-first", goalLongest, sorted); @@ -1859,7 +1859,7 @@ public int compare(UnicodeSet o1, UnicodeSet o2) { return o1.compareTo(o2, ComparisonStyle.LEXICOGRAPHIC); }}); sorted1.addAll(unsorted); - sorted = new ArrayList(sorted1); + sorted = new ArrayList<>(sorted1); assertNotEquals("compareTo-lex", unsorted, sorted); assertEquals("compareTo-lex", goalLex, sorted); @@ -1931,8 +1931,8 @@ public void TestRangeConstructor() { UnicodeSet t = new UnicodeSet(3,5, 7,7); assertEquals("new constructor", w, t); // check to make sure right exceptions are thrown - Class expected = IllegalArgumentException.class; - Class actual; + Class expected = IllegalArgumentException.class; + Class actual; try { actual = null; @@ -2022,7 +2022,7 @@ public void checkModification(UnicodeSet original, boolean isFrozen) { case 0: test.add(0); break; case 1: test.add(0,1); break; case 2: test.add("a"); break; - case 3: List a = new ArrayList(); a.add("a"); test.addAll(a); break; + case 3: List a = new ArrayList<>(); a.add("a"); test.addAll(a); break; case 4: test.addAll("ab"); break; case 5: test.addAll(new UnicodeSet("[ab]")); break; case 6: test.applyIntPropertyValue(0,0); break; @@ -2135,7 +2135,7 @@ public void checkModification(UnicodeSet original, boolean isFrozen) { // } public class TokenSymbolTable implements SymbolTable { - HashMap contents = new HashMap(); + HashMap contents = new HashMap<>(); /** * (Non-SymbolTable API) Add the given variable and value to @@ -2163,8 +2163,8 @@ public void add(String var, char[] body) { @Override public char[] lookup(String s) { logln("TokenSymbolTable: lookup \"" + s + "\" => \"" + - new String((char[]) contents.get(s)) + "\""); - return (char[])contents.get(s); + new String(contents.get(s)) + "\""); + return contents.get(s); } /* (non-Javadoc) diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/normalizer/TestCanonicalIterator.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/normalizer/TestCanonicalIterator.java index 104825d2569b..510d61532c96 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/normalizer/TestCanonicalIterator.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/normalizer/TestCanonicalIterator.java @@ -9,9 +9,9 @@ package com.ibm.icu.dev.test.normalizer; import java.util.Collection; -import java.util.Iterator; import java.util.Set; import java.util.SortedSet; +import java.util.StringJoiner; import java.util.TreeSet; import org.junit.Test; @@ -135,12 +135,12 @@ public void TestBasic() { // check permute // NOTE: we use a TreeSet below to sort the output, which is not guaranteed to be sorted! - Set results = new TreeSet(); + Set results = new TreeSet<>(); CanonicalIterator.permute("ABC", false, results); expectEqual("Simple permutation ", "", collectionToString(results), "ABC, ACB, BAC, BCA, CAB, CBA"); // try samples - SortedSet set = new TreeSet(); + SortedSet set = new TreeSet<>(); for (int i = 0; i < testArray.length; ++i) { //logln("Results for: " + name.transliterate(testArray[i])); CanonicalIterator it = new CanonicalIterator(testArray[i][0]); @@ -263,12 +263,10 @@ private void characterTest(String s, int ch, CanonicalIterator it) } } - static String collectionToString(Collection col) { - StringBuffer result = new StringBuffer(); - Iterator it = col.iterator(); - while (it.hasNext()) { - if (result.length() != 0) result.append(", "); - result.append(it.next().toString()); + static String collectionToString(Collection col) { + StringJoiner result = new StringJoiner(", "); + for (String item : col) { + result.add(item); } return result.toString(); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java index 0c60e946222f..a7210ba12530 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java @@ -499,8 +499,8 @@ public void TestBug12519() { static class T13512Thread extends Thread { private String fText; - public List fBoundaries; - public List fExpectedBoundaries; + public List fBoundaries; + public List fExpectedBoundaries; T13512Thread(String text) { fText = text; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITestMonkey.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITestMonkey.java index 56a4801bea29..994433250beb 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITestMonkey.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITestMonkey.java @@ -55,14 +55,14 @@ public class RBBITestMonkey extends CoreTestFmwk { // abstract static class RBBIMonkeyKind { RBBIMonkeyKind() { - fSets = new ArrayList(); - fClassNames = new ArrayList(); - fAppliedRules = new ArrayList(); + fSets = new ArrayList<>(); + fClassNames = new ArrayList<>(); + fAppliedRules = new ArrayList<>(); } // Return a List of UnicodeSets, representing the character classes used // for this type of iterator. - abstract List charClasses(); + abstract List charClasses(); // Set the test text on which subsequent calls to next() will operate abstract void setText(StringBuffer text); @@ -207,7 +207,7 @@ void setText(StringBuffer s) { } @Override - List charClasses() { + List charClasses() { return fSets; } @@ -476,7 +476,7 @@ static class RBBIWordMonkey extends RBBIMonkeyKind { @Override - List charClasses() { + List charClasses() { return fSets; } @@ -1762,7 +1762,7 @@ private int[] LBNumberCheck(StringBuffer s, int startIdx, int[] retVals) { @Override - List charClasses() { + List charClasses() { return fSets; } } @@ -1845,7 +1845,7 @@ static class RBBISentenceMonkey extends RBBIMonkeyKind { @Override - List charClasses() { + List charClasses() { return fSets; } @@ -2203,7 +2203,7 @@ void RunMonkey(BreakIterator bi, RBBIMonkeyKind mk, String name, int seed, int int TESTSTRINGLEN = 500; StringBuffer testText = new StringBuffer(); int numCharClasses; - List chClasses; + List chClasses; @SuppressWarnings("unused") int expectedCount = 0; boolean[] expectedBreaks = new boolean[TESTSTRINGLEN*2 + 1]; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/shaping/DataDrivenArabicShapingRegTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/shaping/DataDrivenArabicShapingRegTest.java index 2e7beef0c0aa..d7b1d87d4079 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/shaping/DataDrivenArabicShapingRegTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/shaping/DataDrivenArabicShapingRegTest.java @@ -60,7 +60,7 @@ public StandardDataTest(String source, int flags, String expected) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { String lamAlefSpecialVLTR = "\u0020\u0646\u0622\u0644\u0627\u0020\u0646\u0623\u064E\u0644\u0627\u0020" + "\u0646\u0627\u0670\u0644\u0627\u0020\u0646\u0622\u0653\u0644\u0627\u0020" + @@ -390,7 +390,7 @@ public PreflightDataTest(String source, int flags, int length) { } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { {"\u0644\u0627", LETTERS_SHAPE | LENGTH_GROW_SHRINK, 1}, {"\u0644\u0627\u0031", @@ -432,16 +432,16 @@ public void TestPreflight() { public static class ErrorDataTest extends CoreTestFmwk { private String source; private int flags; - private Class error; + private Class error; - public ErrorDataTest(String source, int flags, Class error) { + public ErrorDataTest(String source, int flags, Class error) { this.source = source; this.flags = flags; this.error = error; } @Parameterized.Parameters - public static Collection testData() { + public static Collection testData() { return Arrays.asList(new Object[][] { /* bad data */ {"\u0020\ufef7\u0644\u0020", LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_NEAR, diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/IDNAConformanceTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/IDNAConformanceTest.java index c263039daf09..2bb9632bcd5a 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/IDNAConformanceTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/IDNAConformanceTest.java @@ -15,7 +15,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.HashMap; -import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -38,7 +38,7 @@ public class IDNAConformanceTest extends CoreTestFmwk { @Test public void TestConformance() { - TreeMap inputData = null; + TreeMap> inputData = null; try { inputData = ReadInput.getInputData(); @@ -50,11 +50,8 @@ public void TestConformance() { return; } - Set keyMap = inputData.keySet(); - for (Iterator iter = keyMap.iterator(); iter.hasNext();) { - Long element = (Long) iter.next(); - HashMap tempHash = (HashMap) inputData.get(element); - + Set keyMap = inputData.keySet(); + for (Map tempHash : inputData.values()) { //get all attributes from input data String passfail = (String) tempHash.get("passfail"); String desc = (String) tempHash.get("desc"); @@ -244,16 +241,16 @@ private static String stringReplace(String str) { */ public static class ReadInput { - public static TreeMap getInputData() throws IOException, + public static TreeMap> getInputData() throws IOException, UnsupportedEncodingException { - TreeMap result = new TreeMap(); + TreeMap> result = new TreeMap<>(); BufferedReader in = TestUtil.getDataReader("IDNATestInput.txt", "utf-8"); try { String tempStr = null; int records = 0; boolean firstLine = true; - HashMap hashItem = new HashMap(); + HashMap hashItem = new HashMap<>(); while ((tempStr = in.readLine()) != null) { //ignore the first line if it's "=====" @@ -292,9 +289,9 @@ public static TreeMap getInputData() throws IOException, //if met "=====", it means this item is finished if ("=====".equals(tempStr)) { //set them into result, using records number as key - result.put((long)records, hashItem); + result.put(records, hashItem); //create another hash item and continue - hashItem = new HashMap(); + hashItem = new HashMap<>(); records++; continue; } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/NamePrepTransform.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/NamePrepTransform.java index 5b662041f9dc..a08f047b3cd6 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/NamePrepTransform.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/stringprep/NamePrepTransform.java @@ -185,7 +185,7 @@ private static class MapTransform { boolean initialize(String id, String rule, int direction) { try { - Class cls = Class.forName("com.ibm.icu.text.Transliterator"); + Class cls = Class.forName("com.ibm.icu.text.Transliterator"); Method createMethod = cls.getMethod("createFromRules", String.class, String.class, Integer.TYPE); translitInstance = createMethod.invoke(null, id, rule, direction); translitMethod = cls.getMethod("transliterate", String.class); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/text/SpoofCheckerTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/text/SpoofCheckerTest.java index 9ef1eb11137e..7b849976b565 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/text/SpoofCheckerTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/text/SpoofCheckerTest.java @@ -849,8 +849,8 @@ public void TestDeprecated() { @Test public void testScriptSet() { try { - Class ScriptSet = Class.forName("com.ibm.icu.text.SpoofChecker$ScriptSet"); - Constructor ctor = ScriptSet.getDeclaredConstructor(); + Class ScriptSet = Class.forName("com.ibm.icu.text.SpoofChecker$ScriptSet"); + Constructor ctor = ScriptSet.getDeclaredConstructor(); ctor.setAccessible(true); BitSet ss = (BitSet) ctor.newInstance(); diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java index f069e9ff0a9e..9db505891e6b 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java @@ -48,8 +48,8 @@ public class TimeZoneAliasTest extends CoreTestFmwk { @Test public void TestAliases() { Zone.Seconds seconds = new Zone.Seconds(); - for (Iterator it = Zone.getZoneSet().iterator(); it.hasNext(); ) { - Zone zone = (Zone)it.next(); + for (Iterator it = Zone.getZoneSet().iterator(); it.hasNext(); ) { + Zone zone = it.next(); String id = zone.id; if (id.indexOf('/') < 0 && (id.endsWith("ST") || id.endsWith("DT"))) { if (zone.minRecentOffset != zone.maxRecentOffset) { @@ -59,14 +59,12 @@ public void TestAliases() { + " != " + Zone.formatHours(zone.maxRecentOffset)); } } - Set aliases = zone.getPurportedAliases(); - Set aliasesSet = new TreeSet(aliases); + Set aliases = zone.getPurportedAliases(); + Set aliasesSet = new TreeSet<>(aliases); aliasesSet.add(id); // for comparison - Iterator aliasIterator = aliases.iterator(); - while (aliasIterator.hasNext()) { - String otherId = (String)aliasIterator.next(); + for (String otherId : aliases) { Zone otherZone = Zone.make(otherId); - Set otherAliases = otherZone.getPurportedAliases(); + Set otherAliases = otherZone.getPurportedAliases(); otherAliases.add(otherId); // for comparison if (!aliasesSet.equals(otherAliases)) { errln( @@ -92,8 +90,7 @@ public void TestAliases() { public void TestDifferences() { Zone last = null; Zone.Seconds diffDate = new Zone.Seconds(); - for (Iterator it = Zone.getZoneSet().iterator(); it.hasNext();) { - Zone testZone = (Zone)it.next(); + for (Zone testZone : Zone.getZoneSet()) { if (last != null) { String common = testZone + "\tvs " + last + ":\t"; int diff = testZone.findOffsetOrdering(last, diffDate); @@ -115,8 +112,7 @@ public void TestDifferences() { */ public static void TestGenerateZones() { int count = 1; - for (Iterator it = Zone.getUniqueZoneSet().iterator(); it.hasNext();) { - Zone zone = (Zone)it.next(); + for (Zone zone : Zone.getUniqueZoneSet()) { System.out.println(zone.toString(count++)); } } @@ -129,13 +125,13 @@ static class CollectionJoiner { CollectionJoiner(String separator) { this.separator = separator; } - String join(Collection c) { + String join(Collection c) { StringBuffer result = new StringBuffer(); boolean isFirst = true; - for (Iterator it = c.iterator(); it.hasNext(); ) { + for (String item : c) { if (!isFirst) result.append(separator); else isFirst = false; - result.append(it.next().toString()); + result.append(item); } return result.toString(); } @@ -152,7 +148,7 @@ String join(Collection c) { * avoid expensive comparisons. * @author Davis */ - static class Zone implements Comparable { + static class Zone implements Comparable { // class fields // static private final BagFormatter bf = new BagFormatter().setSeparator(", "); private static final CollectionJoiner bf = new CollectionJoiner(", "); @@ -169,10 +165,10 @@ static class Zone implements Comparable { static private final long recentLimit = getDate((currentYear-1),6,1).getTime(); static private final long startDate = getDate(1905,0,1).getTime(); - static private final Map idToZone = new HashMap(); - static private final Set zoneSet = new TreeSet(); - static private final Set uniqueZoneSet = new TreeSet(); - static private final Map idToRealAliases = new HashMap(); + static private final Map idToZone = new HashMap<>(); + static private final Set zoneSet = new TreeSet<>(); + static private final Set uniqueZoneSet = new TreeSet<>(); + static private final Map> idToRealAliases = new HashMap<>(); // build everything once. static { @@ -183,8 +179,7 @@ static class Zone implements Comparable { Zone last = null; Zone.Seconds diffDate = new Zone.Seconds(); String lastUnique = ""; - for (Iterator it = Zone.getZoneSet().iterator(); it.hasNext();) { - Zone testZone = (Zone)it.next(); + for (Zone testZone : Zone.getZoneSet()) { if (last == null) { uniqueZoneSet.add(testZone); lastUnique = testZone.id; @@ -194,9 +189,9 @@ static class Zone implements Comparable { uniqueZoneSet.add(testZone); lastUnique = testZone.id; } else { - Set aliases = (Set)idToRealAliases.get(lastUnique); + Set aliases = idToRealAliases.get(lastUnique); if (aliases == null) { - aliases = new TreeSet(); + aliases = new TreeSet<>(); idToRealAliases.put(lastUnique, aliases); } aliases.add(testZone.id); @@ -206,16 +201,16 @@ static class Zone implements Comparable { } } - static public Set getZoneSet() { + static public Set getZoneSet() { return zoneSet; } - public static Set getUniqueZoneSet() { + public static Set getUniqueZoneSet() { return uniqueZoneSet; } static public Zone make(String id) { - Zone result = (Zone)idToZone.get(id); + Zone result = idToZone.get(id); if (result != null) return result; result = new Zone(id); idToZone.put(id, result); @@ -344,7 +339,7 @@ public int findOffsetOrdering(Zone other, Seconds dateDiffFound) { private Seconds diffDateReturn = new Seconds(); @Override - public int compareTo(Object o) { + public int compareTo(Zone o) { Zone other = (Zone)o; // first order by max and min offsets // min will usually correspond to standard time, max to daylight @@ -364,8 +359,8 @@ public int compareTo(Object o) { return id.compareTo(other.id); } - public Set getPurportedAliases() { - return new TreeSet(purportedAliases); // clone for safety + public Set getPurportedAliases() { + return new TreeSet<>(purportedAliases); // clone for safety } public boolean isPurportedAlias(String zoneID) { @@ -377,13 +372,13 @@ public boolean isRealAlias(Zone z) { } public String getPurportedAliasesAsString() { - Set s = getPurportedAliases(); + Set s = getPurportedAliases(); if (s.size() == 0) return ""; return " " + bf.join(s); } public String getRealAliasesAsString() { - Set s = (Set)idToRealAliases.get(id); + Set s = idToRealAliases.get(id); if (s == null) return ""; return " *" + bf.join(s); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneTest.java index 7febdd27e3d5..c7065e4ebea2 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/timezone/TimeZoneTest.java @@ -1390,7 +1390,7 @@ public void TestMark(){ TimeZone tz = TimeZone.getTimeZone(tzid); int offset = tz.getOffset(new Date().getTime()); logln(tzid + ":\t" + offset); - List list = Arrays.asList(TimeZone.getAvailableIDs()); + List list = Arrays.asList(TimeZone.getAvailableIDs()); if(!list.contains(tzid)){ errln("Could create the time zone but it is not in getAvailableIDs"); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/DisplayNameTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/DisplayNameTest.java index 0330a7282de2..a2298c3d6a62 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/DisplayNameTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/DisplayNameTest.java @@ -42,9 +42,9 @@ interface DisplayNameGetter { public String get(ULocale locale, String code, Object context); } - Map[] codeToName = new Map[10]; + Map[] codeToName = new Map[10]; { - for (int k = 0; k < codeToName.length; ++k) codeToName[k] = new HashMap(); + for (int k = 0; k < codeToName.length; ++k) codeToName[k] = new HashMap<>(); } static final Object[] zoneFormats = {0, 1, 2, 3, 4, 5, 6, 7}; @@ -82,9 +82,9 @@ public void TestLocales() { * @return */ private String[] getRealZoneIDs() { - Set temp = new TreeSet(Arrays.asList(TimeZone.getAvailableIDs())); + Set temp = new TreeSet<>(Arrays.asList(TimeZone.getAvailableIDs())); temp.removeAll(getAliasMap().keySet()); - return (String[])temp.toArray(new String[temp.size()]); + return temp.toArray(new String[temp.size()]); } @Ignore @@ -141,12 +141,12 @@ public String get(ULocale loc, String code, Object context) { } - Map zoneData = new HashMap(); + Map> zoneData = new HashMap<>(); private String getZoneString(ULocale locale, String olsonID, int item) { - Map data = (Map)zoneData.get(locale); + Map data = zoneData.get(locale); if (data == null) { - data = new HashMap(); + data = new HashMap<>(); if (SHOW_ALL) System.out.println(); if (SHOW_ALL) System.out.println("zones for " + locale); ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(locale); @@ -156,7 +156,7 @@ private String getZoneString(ULocale locale, String olsonID, int item) { //ICUResourceBundle stringSet = table.getWithFallback(String.valueOf(i)); String key = stringSet.getString(0); if (SHOW_ALL) System.out.println("key: " + key); - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); for (int j = 1; j < stringSet.getSize(); ++j) { String entry = stringSet.getString(j); if (SHOW_ALL) System.out.println(" entry: " + entry); @@ -337,8 +337,8 @@ private static String[] getCodes(ULocale locale, String tableName) { ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(locale); ICUResourceBundle table = bundle.getWithFallback(tableName); // copy into array - ArrayList stuff = new ArrayList(); - for (Enumeration keys = table.getKeys(); keys.hasMoreElements();) { + ArrayList stuff = new ArrayList<>(); + for (Enumeration keys = table.getKeys(); keys.hasMoreElements();) { stuff.add(keys.nextElement()); } String[] result = new String[stuff.size()]; @@ -359,19 +359,14 @@ private String[] addUnknown(String[] strings, int len) { return result; } - Map bogusZones = null; - - private Map getAliasMap() { - if (bogusZones == null) { - bogusZones = new TreeMap(); - for (int i = 0; i < zonesAliases.length; ++i) { - bogusZones.put(zonesAliases[i][0], zonesAliases[i][1]); - } + private Map getAliasMap() { + Map bogusZones = new TreeMap<>(); + for (int i = 0; i < zonesAliases.length; ++i) { + bogusZones.put(zonesAliases[i][0], zonesAliases[i][1]); } return bogusZones; } - private void check(String type, ULocale locale, String[] codes, Object[] contextList, DisplayNameGetter getter) { if (contextList == null) contextList = NO_CONTEXT; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceTestSample.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceTestSample.java index c81b7df4335e..8e33b3b8b0e7 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceTestSample.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceTestSample.java @@ -10,9 +10,7 @@ import java.text.Collator; import java.util.EventListener; -import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; @@ -60,13 +58,11 @@ public void helloServiceChanged() { } private void display() { - Map names = HelloService.getDisplayNames(ULocale.US); + Map names = HelloService.getDisplayNames(ULocale.US); System.out.println("displaying " + names.size() + " names."); - Iterator iter = names.entrySet().iterator(); - while (iter.hasNext()) { - Entry entry = (Entry)iter.next(); - String displayName = (String)entry.getKey(); - HelloService service = HelloService.get((String)entry.getValue()); + for (Map.Entry entry : names.entrySet()) { + String displayName = entry.getKey(); + HelloService service = HelloService.get(entry.getValue()); System.out.println(displayName + " says " + service.hello()); try { Thread.sleep(50); @@ -184,11 +180,11 @@ public static HelloService get(String id) { return (HelloService)registry().get(id); } - public static Set getVisibleIDs() { + public static Set getVisibleIDs() { return registry().getVisibleIDs(); } - public static Map getDisplayNames(ULocale locale) { + public static Map getDisplayNames(ULocale locale) { return getDisplayNames(registry(), locale); } @@ -210,7 +206,7 @@ private static void doRegister(String hello, String id) { * uses the default collator for the locale as the comparator to * sort the display names, and null for the matchID. */ - public static SortedMap getDisplayNames(ICUService service, ULocale locale) { + public static SortedMap getDisplayNames(ICUService service, ULocale locale) { Collator col = Collator.getInstance(locale.toLocale()); return service.getDisplayNames(locale, col, null); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java index 7e449e3581e6..ae34d2e9d9ff 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.MissingResourceException; import java.util.Random; import java.util.Set; @@ -71,7 +70,7 @@ public String toString() { * uses the default collator for the locale as the comparator to * sort the display names, and null for the matchID. */ - public static SortedMap getDisplayNames(ICUService service, ULocale locale) { + public static SortedMap getDisplayNames(ICUService service, ULocale locale) { Collator col; try { col = Collator.getInstance(locale.toLocale()); @@ -206,7 +205,7 @@ protected void iterate() { static class UnregisterFactoryThread extends TestThread { private Random r; - List factories; + List factories; UnregisterFactoryThread(String name, ICUService service, long delay) { super("UNREG " + name, service, delay); @@ -257,11 +256,11 @@ static class GetVisibleThread extends TestThread { @Override protected void iterate() { - Set ids = service.getVisibleIDs(); - Iterator iter = ids.iterator(); + Set ids = service.getVisibleIDs(); + Iterator iter = ids.iterator(); int n = 10; while (--n >= 0 && iter.hasNext()) { - String id = (String)iter.next(); + String id = iter.next(); Object result = service.get(id); TestFmwk.logln("iter: " + n + " id: " + id + " result: " + result); } @@ -279,11 +278,11 @@ static class GetDisplayThread extends TestThread { @Override protected void iterate() { - Map names = getDisplayNames(service,locale); - Iterator iter = names.entrySet().iterator(); + Map names = getDisplayNames(service,locale); + Iterator> iter = names.entrySet().iterator(); int n = 10; while (--n >= 0 && iter.hasNext()) { - Entry e = (Entry)iter.next(); + Map.Entry e = iter.next(); String dname = (String)e.getKey(); String id = (String)e.getValue(); Object result = service.get(id); @@ -342,23 +341,22 @@ protected void iterate() { } // return a collection of unique factories, might be fewer than requested - Collection getFactoryCollection(int requested) { - Set locales = new HashSet(); + Collection getFactoryCollection(int requested) { + Set locales = new HashSet<>(); for (int i = 0; i < requested; ++i) { locales.add(getCLV()); } - List factories = new ArrayList(locales.size()); - Iterator iter = locales.iterator(); - while (iter.hasNext()) { - factories.add(new TestFactory((String)iter.next())); + List factories = new ArrayList<>(locales.size()); + Iterator iter = locales.iterator(); + for (String locale : locales) { + factories.add(new TestFactory(locale)); } return factories; } - void registerFactories(ICUService service, Collection c) { - Iterator iter = c.iterator(); - while (iter.hasNext()) { - service.registerFactory((Factory)iter.next()); + void registerFactories(ICUService service, Collection c) { + for (Factory factory : c) { + service.registerFactory(factory); } } @@ -429,13 +427,13 @@ public void Test04_WitheringService() { ICUService service = new ICULocaleService(); if (PRINTSTATS) service.stats(); // Enable the stats collection - Collection fc = getFactoryCollection(50); + Collection fc = getFactoryCollection(50); registerFactories(service, fc); - Factory[] factories = (Factory[])fc.toArray(new Factory[fc.size()]); - Comparator comp = new Comparator() { + Factory[] factories = fc.toArray(new Factory[fc.size()]); + Comparator comp = new Comparator() { @Override - public int compare(Object lhs, Object rhs) { + public int compare(Factory lhs, Factory rhs) { return lhs.toString().compareTo(rhs.toString()); } }; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java index 579b9d9fc58e..f1058a67c838 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java @@ -13,6 +13,7 @@ package com.ibm.icu.dev.test.util; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -611,7 +612,7 @@ public void TestGroupingChildren() { try { Region grouping = Region.getInstance(groupingCode); Set actualChildren = grouping.getContainedRegions(); - List actualChildIDs = new java.util.ArrayList(); + List actualChildIDs = new ArrayList<>(); for (Region childRegion : actualChildren) { actualChildIDs.add(childRegion.toString()); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TestLocaleValidity.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TestLocaleValidity.java index 2142a1537ec9..5d8ae0f0e66a 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TestLocaleValidity.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TestLocaleValidity.java @@ -12,7 +12,6 @@ import java.util.EnumSet; import java.util.LinkedHashSet; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import org.junit.Test; @@ -187,7 +186,7 @@ public void testBasic() { final LinkedHashSet foundKeys = new LinkedHashSet(); check(tests, foundKeys, Datasubtype.regular, Datasubtype.unknown); - LinkedHashSet missing = new LinkedHashSet(KeyTypeData.getBcp47Keys()); + LinkedHashSet missing = new LinkedHashSet<>(KeyTypeData.getBcp47Keys()); missing.removeAll(foundKeys); if (!assertEquals("Missing keys", Collections.EMPTY_SET, missing)) { // print out template for missing cases for adding @@ -313,9 +312,9 @@ public void testValidIdentifierData() { private static void showAll() { Map> data = ValidIdentifiers.getData(); - for (Entry> e1 : data.entrySet()) { + for (Map.Entry> e1 : data.entrySet()) { System.out.println(e1.getKey()); - for (Entry e2 : e1.getValue().entrySet()) { + for (Map.Entry e2 : e1.getValue().entrySet()) { System.out.println("\t" + e2.getKey()); System.out.println("\t\t" + e2.getValue()); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TextTrieMapTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TextTrieMapTest.java index 422edb657064..a360957e54fa 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TextTrieMapTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/TextTrieMapTest.java @@ -87,8 +87,8 @@ public class TextTrieMapTest extends CoreTestFmwk { @Test public void TestCaseSensitive() { - Iterator itr = null; - TextTrieMap map = new TextTrieMap(false); + Iterator itr = null; + TextTrieMap map = new TextTrieMap<>(false); for (int i = 0; i < TESTDATA.length; i++) { map.put((String)TESTDATA[i][0], TESTDATA[i][1]); } @@ -147,8 +147,8 @@ public void TestCaseSensitive() { @Test public void TestCaseInsensitive() { - Iterator itr = null; - TextTrieMap map = new TextTrieMap(true); + Iterator itr = null; + TextTrieMap map = new TextTrieMap<>(true); for (int i = 0; i < TESTDATA.length; i++) { map.put((String)TESTDATA[i][0], TESTDATA[i][1]); } @@ -214,7 +214,7 @@ private boolean eql(Object o1, Object o2) { return o1.equals(o2); } - private void checkResult(String memo, Iterator itr, Object expected) { + private void checkResult(String memo, Iterator itr, Object expected) { if (itr == null) { if (expected != null) { String expectedStr = (expected instanceof Object[]) diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/UtilityTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/UtilityTest.java index cb27835b1273..dd3432fde651 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/UtilityTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/UtilityTest.java @@ -195,8 +195,8 @@ else if (x1 > y1) { @Test public void TestUnicodeSet(){ String[] array = new String[]{"a", "b", "c", "{de}"}; - List list = Arrays.asList(array); - Set aset = new HashSet(list); + List list = Arrays.asList(array); + Set aset = new HashSet<>(list); logln(" *** The source set's size is: " + aset.size()); //The size reads 4 UnicodeSet set = new UnicodeSet();