Skip to content

Commit

Permalink
ICU-22920 Fix raw type warnings in icu4j core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mihnita committed Dec 15, 2024
1 parent 0295105 commit 4ff5d6a
Show file tree
Hide file tree
Showing 35 changed files with 282 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static List<TestDataPair> getTestData(String moduleLocation, String modul
Iterator<TestData> tIter = m.getTestDataIterator();
while (tIter.hasNext()) {
TestData t = tIter.next();
for (Iterator siter = t.getSettingsIterator(); siter.hasNext();) {
for (Iterator<DataMap> siter = t.getSettingsIterator(); siter.hasNext();) {
DataMap settings = (DataMap) siter.next();
list.add(new TestDataPair(t, settings));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestData> getTestDataIterator() {
return new IteratorAdapter<TestData>(testData){
protected TestData prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new UResourceTestData(defaultHeader, nextRes);
}
};
Expand All @@ -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 <T>
*/
private abstract static class IteratorAdapter implements Iterator{
private abstract static class IteratorAdapter<T> implements Iterator<T>{
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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}


Expand Down Expand Up @@ -327,21 +328,21 @@ public DataMap getInfo() {
return info == null ? null : new UTableResource(info);
}

public Iterator getSettingsIterator() {
public Iterator<DataMap> getSettingsIterator() {
assert_is (settings.getType() == UResourceBundle.ARRAY);
return new IteratorAdapter(settings){
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new IteratorAdapter<DataMap>(settings){
protected DataMap prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new UTableResource(nextRes);
}
};
}

public Iterator getDataIterator() {
public Iterator<DataMap> 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<DataMap>(data){
protected DataMap prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new UArrayResource(header, nextRes);
}
};
Expand Down Expand Up @@ -370,15 +371,15 @@ public Object getObject(String key) {
}

private static class UArrayResource implements DataMap{
private Map theMap;
private Map<String, Object> theMap;
UArrayResource(UResourceBundle theHeader, UResourceBundle theData) throws DataModuleFormatError{
assert_is (theHeader != null && theData != null);
String[] header;

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}
Expand All @@ -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 <T> boolean verifySetsIdentical(AbstractTestLog here, Set<T> values1, Set<T> values2) {
if (values1.equals(values2)) return true;
Set temp;
Set<T> 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 <K, V> String show(Map<K, V> 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<K, V> e : m.entrySet()) {
buffer.append(e.getKey() + "=>" + e.getValue() + "\r\n");
}
return buffer.toString();
}
Expand All @@ -184,11 +183,11 @@ public static <T> UnicodeSet getSet(Map<Integer, T> m, T value) {
}
return result;
}
public static String show(Collection c) {

public static <T> String show(Collection<T> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface TestDataModule {
/**
* @return Iterator<TestData>
*/
public Iterator getTestDataIterator();
public Iterator<TestData> getTestDataIterator();

public static class Factory{

Expand Down Expand Up @@ -74,11 +74,11 @@ public static interface TestData {
/**
* @return Iterator<DataMap>
*/
public Iterator getSettingsIterator();
public Iterator<DataMap> getSettingsIterator();
/**
* @return Iterator<DataMap>
*/
public Iterator getDataIterator();
public Iterator<DataMap> getDataIterator();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Moved from UnicodeMapTest
*/
public class UnicodeMapBoilerplateTest extends TestBoilerplate<UnicodeMap> {
public class UnicodeMapBoilerplateTest extends TestBoilerplate<UnicodeMap<String>> {

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

Expand All @@ -32,17 +32,17 @@ 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<String> a, UnicodeMap<String> b) {
// we are pretty confident in the equals method, so won't bother with this right now.
return true;
}

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

0 comments on commit 4ff5d6a

Please sign in to comment.