Skip to content

Commit 4ff5d6a

Browse files
committed
ICU-22920 Fix raw type warnings in icu4j core tests
1 parent 0295105 commit 4ff5d6a

35 files changed

+282
-319
lines changed

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ModuleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static List<TestDataPair> getTestData(String moduleLocation, String modul
7070
Iterator<TestData> tIter = m.getTestDataIterator();
7171
while (tIter.hasNext()) {
7272
TestData t = tIter.next();
73-
for (Iterator siter = t.getSettingsIterator(); siter.hasNext();) {
73+
for (Iterator<DataMap> siter = t.getSettingsIterator(); siter.hasNext();) {
7474
DataMap settings = (DataMap) siter.next();
7575
list.add(new TestDataPair(t, settings));
7676
}

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/ResourceModule.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public TestData getTestData(String testName) throws DataModuleFormatError {
103103
return new UResourceTestData(defaultHeader, testData.get(testName));
104104
}
105105

106-
public Iterator getTestDataIterator() {
107-
return new IteratorAdapter(testData){
108-
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
106+
public Iterator<TestData> getTestDataIterator() {
107+
return new IteratorAdapter<TestData>(testData){
108+
protected TestData prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
109109
return new UResourceTestData(defaultHeader, nextRes);
110110
}
111111
};
@@ -116,11 +116,12 @@ protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatErr
116116
* and return various data-driven test object for next() call
117117
*
118118
* @author Raymond Yang
119+
* @param <T>
119120
*/
120-
private abstract static class IteratorAdapter implements Iterator{
121+
private abstract static class IteratorAdapter<T> implements Iterator<T>{
121122
private UResourceBundle res;
122123
private UResourceBundleIterator itr;
123-
private Object preparedNextElement = null;
124+
private T preparedNextElement = null;
124125
// fix a strange behavior for UResourceBundleIterator for
125126
// UResourceBundle.STRING. It support hasNext(), but does
126127
// not support next() now.
@@ -178,9 +179,9 @@ public boolean hasNext() {
178179
}
179180
}
180181

181-
public Object next(){
182+
public T next(){
182183
if (hasNext()) {
183-
Object t = preparedNextElement;
184+
T t = preparedNextElement;
184185
preparedNextElement = null;
185186
return t;
186187
} else {
@@ -190,7 +191,7 @@ public Object next(){
190191
/**
191192
* To prepare data-driven test object for next() call, should not return null
192193
*/
193-
abstract protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError;
194+
abstract protected T prepareNext(UResourceBundle nextRes) throws DataModuleFormatError;
194195
}
195196

196197

@@ -327,21 +328,21 @@ public DataMap getInfo() {
327328
return info == null ? null : new UTableResource(info);
328329
}
329330

330-
public Iterator getSettingsIterator() {
331+
public Iterator<DataMap> getSettingsIterator() {
331332
assert_is (settings.getType() == UResourceBundle.ARRAY);
332-
return new IteratorAdapter(settings){
333-
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
333+
return new IteratorAdapter<DataMap>(settings){
334+
protected DataMap prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
334335
return new UTableResource(nextRes);
335336
}
336337
};
337338
}
338339

339-
public Iterator getDataIterator() {
340+
public Iterator<DataMap> getDataIterator() {
340341
// unfortunately,
341342
assert_is (data.getType() == UResourceBundle.ARRAY
342343
|| data.getType() == UResourceBundle.STRING);
343-
return new IteratorAdapter(data){
344-
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
344+
return new IteratorAdapter<DataMap>(data){
345+
protected DataMap prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
345346
return new UArrayResource(header, nextRes);
346347
}
347348
};
@@ -370,15 +371,15 @@ public Object getObject(String key) {
370371
}
371372

372373
private static class UArrayResource implements DataMap{
373-
private Map theMap;
374+
private Map<String, Object> theMap;
374375
UArrayResource(UResourceBundle theHeader, UResourceBundle theData) throws DataModuleFormatError{
375376
assert_is (theHeader != null && theData != null);
376377
String[] header;
377378

378379
header = getStringArrayHelper(theHeader);
379380
if (theData.getSize() != header.length)
380381
throw new DataModuleFormatError("The count of Header and Data is mismatch.");
381-
theMap = new HashMap();
382+
theMap = new HashMap<>();
382383
for (int i = 0; i < header.length; i++) {
383384
if(theData.getType()==UResourceBundle.ARRAY){
384385
theMap.put(header[i], theData.get(i));

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestBoilerplate.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ protected boolean _canClone(T a) {
129129
* @return clone
130130
*/
131131
protected T _clone(T a) throws Exception {
132-
Class aClass = a.getClass();
132+
Class<?> aClass = a.getClass();
133133
try {
134134
Method cloner = aClass.getMethod("clone", (Class[])null);
135135
return (T) cloner.invoke(a,(Object[])null);
136136
} catch (NoSuchMethodException e) {
137-
Constructor constructor = aClass.getConstructor(new Class[] {aClass});
137+
Constructor<?> constructor = aClass.getConstructor(new Class[] {aClass});
138138
return (T) constructor.newInstance(new Object[]{a});
139139
}
140140
}
@@ -150,26 +150,25 @@ public static boolean verifySetsIdentical(AbstractTestLog here, UnicodeSet set1,
150150
return false;
151151
}
152152

153-
public static boolean verifySetsIdentical(AbstractTestLog here, Set values1, Set values2) {
153+
public static <T> boolean verifySetsIdentical(AbstractTestLog here, Set<T> values1, Set<T> values2) {
154154
if (values1.equals(values2)) return true;
155-
Set temp;
155+
Set<T> temp;
156156
TestFmwk.errln("Values differ:");
157157
TestFmwk.errln("UnicodeMap - HashMap");
158-
temp = new TreeSet(values1);
158+
temp = new TreeSet<>(values1);
159159
temp.removeAll(values2);
160160
TestFmwk.errln(show(temp));
161161
TestFmwk.errln("HashMap - UnicodeMap");
162-
temp = new TreeSet(values2);
162+
temp = new TreeSet<>(values2);
163163
temp.removeAll(values1);
164164
TestFmwk.errln(show(temp));
165165
return false;
166166
}
167-
168-
public static String show(Map m) {
167+
168+
public static <K, V> String show(Map<K, V> m) {
169169
StringBuilder buffer = new StringBuilder();
170-
for (Iterator it = m.keySet().iterator(); it.hasNext();) {
171-
Object key = it.next();
172-
buffer.append(key + "=>" + m.get(key) + "\r\n");
170+
for (Map.Entry<K, V> e : m.entrySet()) {
171+
buffer.append(e.getKey() + "=>" + e.getValue() + "\r\n");
173172
}
174173
return buffer.toString();
175174
}
@@ -184,11 +183,11 @@ public static <T> UnicodeSet getSet(Map<Integer, T> m, T value) {
184183
}
185184
return result;
186185
}
187-
188-
public static String show(Collection c) {
186+
187+
public static <T> String show(Collection<T> c) {
189188
StringBuilder buffer = new StringBuilder();
190-
for (Iterator it = c.iterator(); it.hasNext();) {
191-
buffer.append(it.next() + "\r\n");
189+
for (T item : c) {
190+
buffer.append(item + "\r\n");
192191
}
193192
return buffer.toString();
194193
}

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/TestDataModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface TestDataModule {
3636
/**
3737
* @return Iterator<TestData>
3838
*/
39-
public Iterator getTestDataIterator();
39+
public Iterator<TestData> getTestDataIterator();
4040

4141
public static class Factory{
4242

@@ -74,11 +74,11 @@ public static interface TestData {
7474
/**
7575
* @return Iterator<DataMap>
7676
*/
77-
public Iterator getSettingsIterator();
77+
public Iterator<DataMap> getSettingsIterator();
7878
/**
7979
* @return Iterator<DataMap>
8080
*/
81-
public Iterator getDataIterator();
81+
public Iterator<DataMap> getDataIterator();
8282
}
8383

8484
/**

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/UnicodeMapBoilerplateTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* Moved from UnicodeMapTest
1919
*/
20-
public class UnicodeMapBoilerplateTest extends TestBoilerplate<UnicodeMap> {
20+
public class UnicodeMapBoilerplateTest extends TestBoilerplate<UnicodeMap<String>> {
2121

2222
private static String[] TEST_VALUES = {"A", "B", "C", "D", "E", "F"};
2323

@@ -32,17 +32,17 @@ public void test() throws Exception {
3232
/* (non-Javadoc)
3333
* @see com.ibm.icu.dev.test.TestBoilerplate#_hasSameBehavior(java.lang.Object, java.lang.Object)
3434
*/
35-
protected boolean _hasSameBehavior(UnicodeMap a, UnicodeMap b) {
35+
protected boolean _hasSameBehavior(UnicodeMap<String> a, UnicodeMap<String> b) {
3636
// we are pretty confident in the equals method, so won't bother with this right now.
3737
return true;
3838
}
3939

4040
/* (non-Javadoc)
4141
* @see com.ibm.icu.dev.test.TestBoilerplate#_addTestObject(java.util.List)
4242
*/
43-
protected boolean _addTestObject(List<UnicodeMap> list) {
43+
protected boolean _addTestObject(List<UnicodeMap<String>> list) {
4444
if (list.size() > 30) return false;
45-
UnicodeMap result = new UnicodeMap();
45+
UnicodeMap<String> result = new UnicodeMap<>();
4646
for (int i = 0; i < 50; ++i) {
4747
int start = random.nextInt(25);
4848
String value = TEST_VALUES[random.nextInt(TEST_VALUES.length)];

0 commit comments

Comments
 (0)