Skip to content

Commit

Permalink
ICU-22920 Fix raw type warnings in icu4j tests: charset, common_tests…
Browse files Browse the repository at this point in the history
…, translit
  • Loading branch information
mihnita committed Dec 18, 2024
1 parent a7291c4 commit ba012a7
Show file tree
Hide file tree
Showing 38 changed files with 271 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@ public void TestSurrogateBehavior() {
int[] badposindices = new int[n];
int[] malfindices = new int[n];
int[] unmapindices = new int[n];
ArrayList pass = new ArrayList();
ArrayList exempt = new ArrayList();
ArrayList<String> pass = new ArrayList<>();
ArrayList<String> exempt = new ArrayList<>();

outer: for (int conv=0; conv<converters.length; conv++) {
String converter = (String)converters[conv];
Expand Down Expand Up @@ -1622,9 +1622,9 @@ public void TestCanConvert(/*String encoding*/)throws Exception {

@Test
public void TestAvailableCharsets() {
SortedMap map = Charset.availableCharsets();
Set keySet = map.keySet();
Iterator iter = keySet.iterator();
SortedMap<String, Charset> map = Charset.availableCharsets();
Set<String> keySet = map.keySet();
Iterator<String> iter = keySet.iterator();
while(iter.hasNext()){
logln("Charset name: "+iter.next().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void conversionTest(TestDataPair pair) {
String testName = td.getName().toString();

// Iterate through and get each of the test case to process
for (Iterator iter = td.getDataIterator(); iter.hasNext();) {
DataMap testcase = (DataMap) iter.next();
for (Iterator<DataMap> iter = td.getDataIterator(); iter.hasNext();) {
DataMap testcase = iter.next();

if (testName.equalsIgnoreCase("toUnicode")) {
TestToUnicode(testcase, testToUnicode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void verifyResultUTF16(String s, List<String> encodings, List<String> re
/* This test is to provide better code coverage for CharsetSelector */
@Test
public void TestCharsetSelectorCodeCoverage() {
List emptyList = new ArrayList();
List<String> emptyList = new ArrayList<>();
UnicodeSet nonEmptySet = new UnicodeSet();

nonEmptySet.add(0x0001, 0x0FFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class AlphabeticIndexTest extends TestFmwk {
private static final String ARROW = "\u2192";
private static final boolean DEBUG = ICUDebug.enabled("alphabeticindex");

public static Set<String> KEY_LOCALES = new LinkedHashSet(Arrays.asList(
public static Set<String> KEY_LOCALES = new LinkedHashSet<>(Arrays.asList(
"en", "es", "de", "fr", "ja", "it", "tr", "pt", "zh", "nl",
"pl", "ar", "ru", "zh_Hant", "ko", "th", "sv", "fi", "da",
"he", "nb", "el", "hr", "bg", "sk", "lt", "vi", "lv", "sr",
Expand Down Expand Up @@ -224,7 +224,7 @@ public void TestA() {
final String probe = test[1];
final String expectedLabel = test[2];
alphabeticIndex.addRecord(probe, 1);
List labels = alphabeticIndex.getBucketLabels();
List<String> labels = alphabeticIndex.getBucketLabels();
logln(labels.toString());
Bucket<Integer> bucket = find(alphabeticIndex, probe);
assertEquals("locale " + test[0] + " name=" + probe + " in bucket",
Expand All @@ -246,7 +246,7 @@ private Bucket<Integer> find(AlphabeticIndex<Integer> alphabeticIndex, final Str
@Test
public void TestFirstCharacters() {

AlphabeticIndex alphabeticIndex = new AlphabeticIndex(Locale.ENGLISH);
AlphabeticIndex<String> alphabeticIndex = new AlphabeticIndex<>(Locale.ENGLISH);
RuleBasedCollator collator = alphabeticIndex.getCollator();
collator.setStrength(Collator.IDENTICAL);
Collection<String> firsts = alphabeticIndex.getFirstCharactersInScripts();
Expand Down Expand Up @@ -316,7 +316,7 @@ public void TestEmpty() {
locales.addAll(Arrays.asList(ULocale.getAvailableLocales()));
for (ULocale locale : locales) {
try {
AlphabeticIndex<String> alphabeticIndex = new AlphabeticIndex(locale);
AlphabeticIndex<String> alphabeticIndex = new AlphabeticIndex<>(locale);
alphabeticIndex.addRecord("hi", "HI");
for (Bucket<String> bucket : alphabeticIndex) {
@SuppressWarnings("unused")
Expand All @@ -331,15 +331,15 @@ public void TestEmpty() {

@Test
public void TestSetGetSpecialLabels() {
AlphabeticIndex index = new AlphabeticIndex(Locale.GERMAN).addLabels(new Locale("ru"));
AlphabeticIndex<String> index = new AlphabeticIndex<String>(Locale.GERMAN).addLabels(new Locale("ru"));
index.setUnderflowLabel("__");
index.setInflowLabel("--");
index.setOverflowLabel("^^");
assertEquals("underflow label", "__", index.getUnderflowLabel());
assertEquals("inflow label", "--", index.getInflowLabel());
assertEquals("overflow label", "^^", index.getOverflowLabel());

ImmutableIndex ii = index.buildImmutableIndex();
ImmutableIndex<String> ii = index.buildImmutableIndex();
assertEquals("0 -> underflow", "__", ii.getBucket(ii.getBucketIndex("0")).getLabel());
assertEquals("Ω -> inflow", "--", ii.getBucket(ii.getBucketIndex("Ω")).getLabel());
assertEquals("字 -> overflow", "^^", ii.getBucket(ii.getBucketIndex("字")).getLabel());
Expand All @@ -357,15 +357,15 @@ public void TestInflow() {
};
for (Object[] test : tests) {
int expected = (Integer) test[0];
AlphabeticIndex<Double> alphabeticIndex = new AlphabeticIndex((ULocale)test[1]);
AlphabeticIndex<Double> alphabeticIndex = new AlphabeticIndex<>((ULocale)test[1]);
for (int i = 2; i < test.length; ++i) {
if (test[i] instanceof ULocale) {
alphabeticIndex.addLabels((ULocale)test[i]);
} else {
alphabeticIndex.addLabels((UnicodeSet)test[i]);
}
}
Counter<AlphabeticIndex.Bucket.LabelType> counter = new Counter();
Counter<LabelType> counter = new Counter<>();
for (Bucket<Double> bucket : alphabeticIndex) {
LabelType labelType = bucket.getLabelType();
counter.add(labelType, 1);
Expand All @@ -375,7 +375,7 @@ public void TestInflow() {
assertEquals(LabelType.INFLOW + "\t" + printList, expected, counter.get(LabelType.INFLOW));
if (expected != counter.get(LabelType.INFLOW)) {
// for debugging
AlphabeticIndex<Double> indexCharacters2 = new AlphabeticIndex((ULocale)test[1]);
AlphabeticIndex<Double> indexCharacters2 = new AlphabeticIndex<>((ULocale)test[1]);
for (int i = 2; i < test.length; ++i) {
if (test[i] instanceof ULocale) {
indexCharacters2.addLabels((ULocale)test[i]);
Expand All @@ -398,7 +398,7 @@ private void checkBuckets(String localeString, String[] test, ULocale additional
// Create a simple index where the values for the strings are Integers, and add the strings
AlphabeticIndex<Integer> index = new AlphabeticIndex<Integer>(desiredLocale).addLabels(additionalLocale);
int counter = 0;
Counter<String> itemCount = new Counter();
Counter<String> itemCount = new Counter<>();
for (String item : test) {
index.addRecord(item, counter++);
itemCount.add(item, 1);
Expand Down Expand Up @@ -524,7 +524,7 @@ private void showLabelInList(StringBuilder buffer, String label) {

private Counter<String> getKeys(AlphabeticIndex.Bucket<Integer> entry) {
Counter<String> keys = new Counter<String>();
for (AlphabeticIndex.Record x : entry) {
for (AlphabeticIndex.Record<Integer> x : entry) {
String key = x.getName().toString();
keys.add(key, 1);
}
Expand All @@ -536,7 +536,7 @@ public void TestIndexCharactersList() {
for (String[] localeAndIndexCharacters : localeAndIndexCharactersLists) {
ULocale locale = new ULocale(localeAndIndexCharacters[0]);
String expectedIndexCharacters = "\u2026:" + localeAndIndexCharacters[1] + ":\u2026";
Collection<String> alphabeticIndex = new AlphabeticIndex(locale).getBucketLabels();
Collection<String> alphabeticIndex = new AlphabeticIndex<>(locale).getBucketLabels();

// Join the elements of the list to a string with delimiter ":"
StringBuilder sb = new StringBuilder();
Expand All @@ -561,7 +561,7 @@ public void TestBasics() {
ULocale[] list = ULocale.getAvailableLocales();
// get keywords combinations
// don't bother with multiple combinations at this point
List keywords = new ArrayList();
List<String> keywords = new ArrayList<>();
keywords.add("");

String[] collationValues = Collator.getKeywordValues("collation");
Expand All @@ -570,8 +570,7 @@ public void TestBasics() {
}

for (int i = 0; i < list.length; ++i) {
for (Iterator it = keywords.iterator(); it.hasNext();) {
String collationValue = (String) it.next();
for (String collationValue : keywords) {
String localeString = list[i].toString();
if (!KEY_LOCALES.contains(localeString)) continue; // TODO change in exhaustive
ULocale locale = new ULocale(localeString + collationValue);
Expand All @@ -584,13 +583,13 @@ public void TestBasics() {
continue;
}
boolean isUnihan = collationValue.contains("unihan");
AlphabeticIndex alphabeticIndex = new AlphabeticIndex(locale);
AlphabeticIndex<String> alphabeticIndex = new AlphabeticIndex<>(locale);
if (isUnihan) {
// Unihan tailorings have a label per radical, and there are at least 214,
// if not more when simplified radicals are distinguished.
alphabeticIndex.setMaxLabelCount(500);
}
final Collection mainChars = alphabeticIndex.getBucketLabels();
final Collection<String> mainChars = alphabeticIndex.getBucketLabels();
String mainCharString = mainChars.toString();
if (mainCharString.length() > 500) {
mainCharString = mainCharString.substring(0,500) + "...";
Expand Down Expand Up @@ -687,7 +686,7 @@ public void TestClientSupport() {
@Test
public void TestFirstScriptCharacters() {
Collection<String> firstCharacters =
new AlphabeticIndex(ULocale.ENGLISH).getFirstCharactersInScripts();
new AlphabeticIndex<>(ULocale.ENGLISH).getFirstCharactersInScripts();
Collection<String> expectedFirstCharacters = firstStringsInScript((RuleBasedCollator) Collator.getInstance(ULocale.ROOT));
Collection<String> diff = new TreeSet<String>(firstCharacters);
diff.removeAll(expectedFirstCharacters);
Expand Down Expand Up @@ -923,7 +922,7 @@ public void TestTraditional() {
public void TestHaniFirst() {
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.ROOT);
coll.setReorderCodes(UScript.HAN);
AlphabeticIndex index = new AlphabeticIndex(coll);
AlphabeticIndex<String> index = new AlphabeticIndex<>(coll);
assertEquals("getBucketCount()", 1, index.getBucketCount()); // ... (underflow only)
index.addLabels(Locale.ENGLISH);
assertEquals("getBucketCount()", 28, index.getBucketCount()); // ... A-Z ...
Expand All @@ -947,7 +946,7 @@ public void TestHaniFirst() {
public void TestPinyinFirst() {
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.CHINESE);
coll.setReorderCodes(UScript.HAN);
AlphabeticIndex index = new AlphabeticIndex(coll);
AlphabeticIndex<String> index = new AlphabeticIndex<>(coll);
assertEquals("getBucketCount()", 28, index.getBucketCount()); // ... A-Z ...
index.addLabels(Locale.CHINESE);
assertEquals("getBucketCount()", 28, index.getBucketCount()); // ... A-Z ...
Expand All @@ -969,10 +968,10 @@ public void TestPinyinFirst() {
*/
@Test
public void TestSchSt() {
AlphabeticIndex index = new AlphabeticIndex(ULocale.GERMAN);
AlphabeticIndex<String> index = new AlphabeticIndex<>(ULocale.GERMAN);
index.addLabels(new UnicodeSet("[Æ{Sch*}{St*}]"));
// ... A Æ B-R S Sch St T-Z ...
ImmutableIndex immIndex = index.buildImmutableIndex();
ImmutableIndex<String> immIndex = index.buildImmutableIndex();
assertEquals("getBucketCount()", 31, index.getBucketCount());
assertEquals("immutable getBucketCount()", 31, immIndex.getBucketCount());
String[][] testCases = new String[][] {
Expand Down Expand Up @@ -1028,8 +1027,8 @@ public void TestNoLabels() {
*/
@Test
public void TestChineseZhuyin() {
AlphabeticIndex index = new AlphabeticIndex(ULocale.forLanguageTag("zh-u-co-zhuyin"));
ImmutableIndex immIndex = index.buildImmutableIndex();
AlphabeticIndex<String> index = new AlphabeticIndex<>(ULocale.forLanguageTag("zh-u-co-zhuyin"));
ImmutableIndex<String> immIndex = index.buildImmutableIndex();
assertEquals("getBucketCount()", 38, immIndex.getBucketCount()); // ... ㄅ ㄆ ㄇ ㄈ ㄉ -- ㄩ ...
assertEquals("label 1", "ㄅ", immIndex.getBucket(1).getLabel());
assertEquals("label 2", "ㄆ", immIndex.getBucket(2).getLabel());
Expand All @@ -1040,8 +1039,8 @@ public void TestChineseZhuyin() {

@Test
public void TestJapaneseKanji() {
AlphabeticIndex index = new AlphabeticIndex(ULocale.JAPANESE);
AlphabeticIndex.ImmutableIndex immIndex = index.buildImmutableIndex();
AlphabeticIndex<String> index = new AlphabeticIndex<>(ULocale.JAPANESE);
AlphabeticIndex.ImmutableIndex<String> immIndex = index.buildImmutableIndex();
// There are no index characters for Kanji in the Japanese standard collator.
// They should all go into the overflow bucket.
final int[] kanji = { 0x4E9C, 0x95C7, 0x4E00, 0x58F1 };
Expand All @@ -1061,17 +1060,17 @@ public void TestFrozenCollator() {
// The AlphabeticIndex constructor used to throw an exception
// because it cloned the collator (which preserves frozenness)
// and set the clone's strength to PRIMARY.
AlphabeticIndex index = new AlphabeticIndex(coll);
AlphabeticIndex<String> index = new AlphabeticIndex<>(coll);
assertEquals("same strength as input Collator",
Collator.IDENTICAL, index.getCollator().getStrength());
}

@Test
public void TestChineseUnihan() {
AlphabeticIndex index = new AlphabeticIndex(new ULocale("zh-u-co-unihan"));
AlphabeticIndex<String> index = new AlphabeticIndex<>(new ULocale("zh-u-co-unihan"));
index.setMaxLabelCount(500); // ICU 54 default is 99.
assertEquals("getMaxLabelCount()", 500, index.getMaxLabelCount()); // code coverage
AlphabeticIndex.ImmutableIndex immIndex = index.buildImmutableIndex();
AlphabeticIndex.ImmutableIndex<String> immIndex = index.buildImmutableIndex();
int bucketCount = immIndex.getBucketCount();
if(bucketCount < 216) {
// There should be at least an underflow and overflow label,
Expand All @@ -1095,8 +1094,8 @@ public void TestChineseUnihan() {

@Test
public void testAddLabels_Locale() {
AlphabeticIndex<?> ulocaleIndex = new AlphabeticIndex<String>(ULocale.CANADA);
AlphabeticIndex<?> localeIndex = new AlphabeticIndex<String>(Locale.CANADA);
AlphabeticIndex<?> ulocaleIndex = new AlphabeticIndex<>(ULocale.CANADA);
AlphabeticIndex<?> localeIndex = new AlphabeticIndex<>(Locale.CANADA);
ulocaleIndex.addLabels(ULocale.SIMPLIFIED_CHINESE);
localeIndex.addLabels(Locale.SIMPLIFIED_CHINESE);
assertEquals("getBucketLables() results of ulocaleIndex and localeIndex differ",
Expand Down Expand Up @@ -1171,12 +1170,12 @@ public void testHasBuckets() {
}

private void checkHasBuckets(Locale locale, int script) {
AlphabeticIndex.ImmutableIndex index =
AlphabeticIndex.ImmutableIndex<String> index =
new AlphabeticIndex<String>(locale).buildImmutableIndex();
String loc = locale.toString();
assertTrue(loc + " at least 3 buckets", index.getBucketCount() >= 3);
AlphabeticIndex.Bucket bucket = index.getBucket(1);
assertEquals(loc + " real bucket", AlphabeticIndex.Bucket.LabelType.NORMAL,
AlphabeticIndex.Bucket<String> bucket = index.getBucket(1);
assertEquals(loc + " real bucket", LabelType.NORMAL,
bucket.getLabelType());
assertEquals(loc + " expected script", script,
UScript.getScript(bucket.getLabel().codePointAt(0)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ public void TestJB5298(){
}
}

Set foundValues = new TreeSet(Arrays.asList(values));
Set<String> foundValues = new TreeSet<>(Arrays.asList(values));

for (int i = 0; i < locales.length; ++i) {
for (int j = 0; j < values.length; ++j) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ public void Test4179686() throws Exception {
String text = "T\u00f6ne"; // o-umlaut

CollationElementIterator iter = coll.getCollationElementIterator(text);
List elements = new ArrayList();
List<Integer> elements = new ArrayList<>();
int elem;

// Iterate forward and collect all of the elements into a Vector
Expand All @@ -1084,7 +1084,7 @@ public void Test4179686() throws Exception {
iter.reset();
int index = elements.size() - 1;
while ((elem = iter.previous()) != CollationElementIterator.NULLORDER) {
int expect = ((Integer)elements.get(index)).intValue();
int expect = (elements.get(index)).intValue();

if (elem != expect) {
errln("Mismatch at index " + index
Expand Down
Loading

0 comments on commit ba012a7

Please sign in to comment.