diff --git a/icu4j/main/classes/charset/src/com/ibm/icu/charset/UConverterDataReader.java b/icu4j/main/classes/charset/src/com/ibm/icu/charset/UConverterDataReader.java index 842cb328e7..457a597668 100644 --- a/icu4j/main/classes/charset/src/com/ibm/icu/charset/UConverterDataReader.java +++ b/icu4j/main/classes/charset/src/com/ibm/icu/charset/UConverterDataReader.java @@ -407,7 +407,6 @@ final class UConverterDataReader { //private final static boolean debug = ICUDebug.enabled("UConverterDataReader"); private static final class IsAcceptable implements ICUBinary.Authenticate { - // @Override when we switch to Java 6 @Override public boolean isDataVersionAcceptable(byte formatVersion[]) { return formatVersion[0] == 6; diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationSettings.java b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationSettings.java index 34865c017d..4f7f40a7e5 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationSettings.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationSettings.java @@ -137,9 +137,7 @@ public final class CollationSettings extends SharedObject { if(codesLength == codesAndRanges.length) { codes = codesAndRanges; } else { - // TODO: Java 6: Arrays.copyOf(codes, codesLength); - codes = new int[codesLength]; - System.arraycopy(codesAndRanges, 0, codes, 0, codesLength); + codes = Arrays.copyOf(codesAndRanges, codesLength); } int rangesStart = codesLength; int rangesLimit = codesAndRanges.length; diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/text/RuleBasedCollator.java b/icu4j/main/classes/collate/src/com/ibm/icu/text/RuleBasedCollator.java index bd4e833e5c..846c2e096f 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/text/RuleBasedCollator.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/text/RuleBasedCollator.java @@ -1861,7 +1861,6 @@ public final class RuleBasedCollator extends Collator { assert (valid == null) == (actual == null); // Another check we could do is that the actual locale is at // the same level or less specific than the valid locale. - // TODO: Starting with Java 7, use Objects.equals(a, b). if(Objects.equals(actual, tailoring.actualLocale)) { actualLocaleIsSameAsValid = false; } else { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUBinary.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUBinary.java index 98a1d0bb4e..76326bb075 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUBinary.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUBinary.java @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.MissingResourceException; import java.util.Set; @@ -277,7 +278,7 @@ public final class ICUBinary { } } - private static final List icuDataFiles = new ArrayList(); + private static final List icuDataFiles = new ArrayList<>(); static { // Normally com.ibm.icu.impl.ICUBinary.dataPath. @@ -733,10 +734,7 @@ public final class ICUBinary { } else if (capacity < 0x4000) { capacity *= 2; // Grow faster until we reach 16kB. } - // TODO Java 6 replace new byte[] and arraycopy(): bytes = Arrays.copyOf(bytes, capacity); - byte[] newBytes = new byte[capacity]; - System.arraycopy(bytes, 0, newBytes, 0, length); - bytes = newBytes; + bytes = Arrays.copyOf(bytes, capacity); bytes[length++] = (byte) nextByte; } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java index e4b30ecfe7..5976f3518b 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java @@ -14,6 +14,7 @@ import java.lang.ref.SoftReference; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.IntBuffer; +import java.util.Arrays; import com.ibm.icu.util.ICUException; import com.ibm.icu.util.ICUUncheckedIOException; @@ -1167,7 +1168,7 @@ public final class ICUResourceBundleReader { return value; } values[index] = CacheValue.futureInstancesWillBeStrong() ? - item : new SoftReference(item); + item : new SoftReference<>(item); return item; } @@ -1216,7 +1217,7 @@ public final class ICUResourceBundleReader { return level.putIfAbsent(key, item, size); } keys[index] = key; - values[index] = storeDirectly(size) ? item : new SoftReference(item); + values[index] = storeDirectly(size) ? item : new SoftReference<>(item); return item; } // Collision: Add a child level, move the old item there, @@ -1285,29 +1286,7 @@ public final class ICUResourceBundleReader { } private int findSimple(int key) { - // With Java 6, return Arrays.binarySearch(keys, 0, length, key). - int start = 0; - int limit = length; - while((limit - start) > 8) { - int mid = (start + limit) / 2; - if(key < keys[mid]) { - limit = mid; - } else { - start = mid; - } - } - // For a small number of items, linear search should be a little faster. - while(start < limit) { - int k = keys[start]; - if(key < k) { - return ~start; - } - if(key == k) { - return start; - } - ++start; - } - return ~start; + return Arrays.binarySearch(keys, 0, length, key); } @SuppressWarnings("unchecked") @@ -1348,7 +1327,7 @@ public final class ICUResourceBundleReader { } ++length; keys[index] = res; - values[index] = storeDirectly(size) ? item : new SoftReference(item); + values[index] = storeDirectly(size) ? item : new SoftReference<>(item); return item; } else /* not found && length == SIMPLE_LENGTH */ { // Grow to become trie-like. diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java index a43d3f587d..b078c78f43 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java @@ -10,8 +10,6 @@ package com.ibm.icu.impl; import java.io.IOException; import java.io.ObjectInputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Date; import java.util.TreeSet; @@ -35,22 +33,13 @@ public class JavaTimeZone extends TimeZone { private java.util.TimeZone javatz; private transient java.util.Calendar javacal; - private static Method mObservesDaylightTime; static { - AVAILABLESET = new TreeSet(); + AVAILABLESET = new TreeSet<>(); String[] availableIds = java.util.TimeZone.getAvailableIDs(); for (int i = 0; i < availableIds.length; i++) { AVAILABLESET.add(availableIds[i]); } - - try { - mObservesDaylightTime = java.util.TimeZone.class.getMethod("observesDaylightTime", (Class[]) null); - } catch (NoSuchMethodException e) { - // Java 6 or older - } catch (SecurityException e) { - // not visible - } } /** @@ -198,16 +187,7 @@ public class JavaTimeZone extends TimeZone { */ @Override public boolean observesDaylightTime() { - if (mObservesDaylightTime != null) { - // Java 7+ - try { - return (Boolean)mObservesDaylightTime.invoke(javatz, (Object[]) null); - } catch (IllegalAccessException e) { - } catch (IllegalArgumentException e) { - } catch (InvocationTargetException e) { - } - } - return super.observesDaylightTime(); + return javatz.observesDaylightTime(); } /* (non-Javadoc) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java index 3d30dfa2df..1c4e890efa 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java @@ -1283,7 +1283,6 @@ public final class UCharacterProperty } private static final class IsAcceptable implements ICUBinary.Authenticate { - // @Override when we switch to Java 6 @Override public boolean isDataVersionAcceptable(byte version[]) { return version[0] == 7; diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/UPropertyAliases.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/UPropertyAliases.java index 16e930c3d2..36bbfaef7c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/UPropertyAliases.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/UPropertyAliases.java @@ -68,7 +68,6 @@ public final class UPropertyAliases { private String nameGroups; private static final class IsAcceptable implements ICUBinary.Authenticate { - // @Override when we switch to Java 6 @Override public boolean isDataVersionAcceptable(byte version[]) { return version[0]==2; diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java index 9934dc7f31..36c8d44293 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java @@ -64,7 +64,7 @@ public class Currency extends MeasureUnit { // Cache to save currency name trie private static ICUCache>> CURRENCY_NAME_CACHE = - new SimpleCache>>(); + new SimpleCache<>(); /** * Selector for getName() indicating a symbolic name for a @@ -229,7 +229,7 @@ public class Currency extends MeasureUnit { public static Set getAvailableCurrencies() { CurrencyMetaInfo info = CurrencyMetaInfo.getInstance(); List list = info.currencies(CurrencyFilter.all()); - HashSet resultSet = new HashSet(list.size()); + HashSet resultSet = new HashSet<>(list.size()); for (String code : list) { resultSet.add(getInstance(code)); } @@ -657,7 +657,6 @@ public class Currency extends MeasureUnit { * @see #getName(Locale, int, boolean[]) * @stable ICU 49 */ - @SuppressWarnings("javadoc") // java.util.Currency#getDisplayName() is introduced in Java 7 public String getDisplayName() { return getName(Locale.getDefault(), LONG_NAME, null); } @@ -677,7 +676,6 @@ public class Currency extends MeasureUnit { * @see #getName(Locale, int, boolean[]) * @stable ICU 49 */ - @SuppressWarnings("javadoc") // java.util.Currency#getDisplayName() is introduced in Java 7 public String getDisplayName(Locale locale) { return getName(locale, LONG_NAME, null); } @@ -748,10 +746,10 @@ public class Currency extends MeasureUnit { List> currencyTrieVec = CURRENCY_NAME_CACHE.get(locale); if (currencyTrieVec == null) { TextTrieMap currencyNameTrie = - new TextTrieMap(true); + new TextTrieMap<>(true); TextTrieMap currencySymbolTrie = - new TextTrieMap(false); - currencyTrieVec = new ArrayList>(); + new TextTrieMap<>(false); + currencyTrieVec = new ArrayList<>(); currencyTrieVec.add(currencySymbolTrie); currencyTrieVec.add(currencyNameTrie); setupCurrencyTrieVec(locale, currencyTrieVec); @@ -971,7 +969,7 @@ public class Currency extends MeasureUnit { //CurrencyFilter filter = CurrencyFilter.onDateRange(null, new Date(253373299200000L)); CurrencyFilter filter = CurrencyFilter.all(); all = Collections.unmodifiableList(getTenderCurrencies(filter)); - ALL_TENDER_CODES = new SoftReference>(all); + ALL_TENDER_CODES = new SoftReference<>(all); } return all; } @@ -981,8 +979,8 @@ public class Currency extends MeasureUnit { if (all == null) { CurrencyMetaInfo info = CurrencyMetaInfo.getInstance(); all = Collections.unmodifiableSet( - new HashSet(info.currencies(CurrencyFilter.all()))); - ALL_CODES_AS_SET = new SoftReference>(all); + new HashSet<>(info.currencies(CurrencyFilter.all()))); + ALL_CODES_AS_SET = new SoftReference<>(all); } return all; } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java index dc2352a9ab..c7a2e8d545 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java @@ -541,7 +541,7 @@ abstract public class TimeZone implements Serializable, Cloneable, Freezable timeType = new Output(TimeType.UNKNOWN); + Output timeType = new Output<>(TimeType.UNKNOWN); switch (style) { case GENERIC_LOCATION: @@ -673,7 +673,6 @@ abstract public class TimeZone implements Serializable, Cloneable, Freezable splocs = new HashMap(); + Map splocs = new HashMap<>(); for (Locale spLoc : SPECIAL_LOCALES) { String var = spLoc.getVariant(); if (var.length() > 0) { @@ -131,7 +131,7 @@ public class ICULocaleServiceProvider { return LOCALES; } - Set localeSet = new HashSet(); + Set localeSet = new HashSet<>(); ULocale[] icuLocales = ICUResourceBundle.getAvailableULocales(); for (ULocale uloc : icuLocales) { @@ -183,14 +183,6 @@ public class ICULocaleServiceProvider { } private static void addULocale(ULocale uloc, Set locales) { - // special case - nn - // ULocale#toLocale on Java 6 maps "nn" to "no_NO_NY" - if (uloc.getLanguage().equals("nn") && uloc.getScript().length() == 0) { - Locale locNN = new Locale(uloc.getLanguage(), uloc.getCountry(), uloc.getVariant()); - addLocale(locNN, locales); - return; - } - locales.add(uloc.toLocale()); if (enableIcuVariants()) { diff --git a/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/CurrencyNameProviderICU.java b/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/CurrencyNameProviderICU.java index b359dbc84e..8093b779d7 100644 --- a/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/CurrencyNameProviderICU.java +++ b/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/CurrencyNameProviderICU.java @@ -26,8 +26,7 @@ public class CurrencyNameProviderICU extends CurrencyNameProvider { return sym; } - // Not available in Java 6 - // @Override + @Override public String getDisplayName(String currencyCode, Locale locale) { CurrencyDisplayNames curDispNames = CurrencyDisplayNames.getInstance(ICULocaleServiceProvider.toULocaleNoSpecialVariant(locale)); String name = curDispNames.getName(currencyCode); diff --git a/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/LocaleNameProviderICU.java b/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/LocaleNameProviderICU.java index d25854eae0..ffa4478870 100644 --- a/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/LocaleNameProviderICU.java +++ b/icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/LocaleNameProviderICU.java @@ -39,8 +39,7 @@ public class LocaleNameProviderICU extends LocaleNameProvider { return disp; } - // Not available in Java 6 - // @Override + @Override public String getDisplayScript(String scriptCode, Locale locale) { scriptCode = AsciiUtil.toTitleString(scriptCode); String disp = LocaleDisplayNames.getInstance(ICULocaleServiceProvider.toULocaleNoSpecialVariant(locale)) diff --git a/icu4j/main/shared/build/common-targets.xml b/icu4j/main/shared/build/common-targets.xml index 56ea12c546..8ee10ed141 100644 --- a/icu4j/main/shared/build/common-targets.xml +++ b/icu4j/main/shared/build/common-targets.xml @@ -25,7 +25,7 @@ - + diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDateFormatAPI.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDateFormatAPI.java index 8e950686f7..eb263df18b 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDateFormatAPI.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDateFormatAPI.java @@ -29,8 +29,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.dev.test.TestUtil; -import com.ibm.icu.dev.test.TestUtil.JavaVendor; import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.NumberFormat; import com.ibm.icu.util.Calendar; @@ -158,15 +156,16 @@ public class IntlTestDateFormatAPI extends TestFmwk long count = locales.length; logln("Got " + count + " locales" ); - // Ticket #6280, #8078 and #11674 - // These locales should be included in the result - boolean missingLocaleNotFatal = - TestUtil.getJavaVendor() == JavaVendor.Android || TestUtil.getJavaVersion() >= 7; + // These test cases used to check Locales without a script tag. + // Java 6 Locale did not support script tags, such as zh_CN and zh_TW. + // Because ICU 63+ supports Java 7 as minimum Java version, sample + // Locales below were updated with ones with script tags. + // See ticket #6280, #8078 and #11674 for the history. final Locale[] samples = { - new Locale("zh", "CN"), - new Locale("zh", "TW"), - new Locale("zh", "HK"), - new Locale("sr", "RS"), + Locale.forLanguageTag("zh-Hans-CN"), + Locale.forLanguageTag("zh-Hant-TW"), + Locale.forLanguageTag("zh-Hant-HK"), + Locale.forLanguageTag("sr-Cyrl-RS"), }; boolean[] available = new boolean[samples.length]; for(int i = 0; i < count; i++) { @@ -182,13 +181,7 @@ public class IntlTestDateFormatAPI extends TestFmwk } for (int i = 0; i < available.length; i++) { if (!available[i]) { - if (missingLocaleNotFatal) { - // Java 7 supports script field, so zh_Hans_CN is included - // in the available locale list. - logln("INFO: missing Locale: " + samples[i]); - } else { - errln("ERROR: missing Locale: " + samples[i]); - } + errln("ERROR: missing Locale: " + samples[i]); } } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java index 78845b3641..2935a437cc 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java @@ -218,13 +218,13 @@ public class TestUScript extends TestFmwk { UnicodeSet scriptSet = new UnicodeSet(); scriptSet.applyIntPropertyValue(UProperty.SCRIPT, sc); if(usage == ScriptUsage.NOT_ENCODED) { - assertTrue(sn + " not encoded, no sample", sample.length() == 0); // Java 6: sample.isEmpty() + assertTrue(sn + " not encoded, no sample", sample.isEmpty()); assertFalse(sn + " not encoded, not RTL", UScript.isRightToLeft(sc)); assertFalse(sn + " not encoded, not LB letters", UScript.breaksBetweenLetters(sc)); assertFalse(sn + " not encoded, not cased", UScript.isCased(sc)); assertTrue(sn + " not encoded, no characters", scriptSet.isEmpty()); } else { - assertFalse(sn + " encoded, has a sample character", sample.length() == 0); // Java 6: sample.isEmpty() + assertFalse(sn + " encoded, has a sample character", sample.isEmpty()); int firstChar = sample.codePointAt(0); int charScript = getCharScript(sc); assertEquals(sn + " script(sample(script))", diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBIMonkeyTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBIMonkeyTest.java index 9ddb73bd0d..3637b68850 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBIMonkeyTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBIMonkeyTest.java @@ -73,10 +73,10 @@ public class RBBIMonkeyTest extends TestFmwk { static class BreakRules { BreakRules(RBBIMonkeyImpl monkeyImpl) { fMonkeyImpl = monkeyImpl; - fBreakRules = new ArrayList(); + fBreakRules = new ArrayList<>(); fType = BreakIterator.KIND_TITLE; - fCharClasses = new HashMap(); - fCharClassList = new ArrayList(); + fCharClasses = new HashMap<>(); + fCharClassList = new ArrayList<>(); fDictionarySet = new UnicodeSet(); // Match an alpha-numeric identifier in a rule. Will be a set name. @@ -293,25 +293,12 @@ public class RBBIMonkeyTest extends TestFmwk { thisRule.fExpandedRule = thisRule.fExpandedRule.replace("[]", "[a&&[^a]]"); - // Change Unicode escape syntax for compatibility with Java regular expressions (Java 7 or newer) + // Change Unicode escape syntax for compatibility with Java regular expressions // \udddd => \x{dddd} // \U00hhhhhh => \x{hhhhhh} - // thisRule.fExpandedRule = thisRule.fExpandedRule.replaceAll("\\\\u([0-9A-Fa-f]{4})", "\\\\x{$1}"); - // thisRule.fExpandedRule = thisRule.fExpandedRule.replaceAll("\\\\U00([0-9A-Fa-f]{6})", "\\\\x{$1}"); - - // Java 6 compatibility troubles - there is no syntax for escaping a supplementary character - // within a regular expression character class. Put them in as unescaped literal chars. - StringBuilder sb = new StringBuilder(thisRule.fExpandedRule); - while (true) { - int where = sb.indexOf("\\U00"); - if (where < 0) { - break; - } - String cp = hexToCodePoint(sb.substring(where+2, where+10)); - sb.replace(where, where+10, cp); - } - thisRule.fExpandedRule = sb.toString(); + thisRule.fExpandedRule = thisRule.fExpandedRule.replaceAll("\\\\u([0-9A-Fa-f]{4})", "\\\\x{$1}"); + thisRule.fExpandedRule = thisRule.fExpandedRule.replaceAll("\\\\U00([0-9A-Fa-f]{6})", "\\\\x{$1}"); // Escape any literal '#' in the rule expression. Without escaping, these introduce a comment. // UnicodeSet._generatePattern() inserts un-escaped "#"s @@ -1014,7 +1001,7 @@ public class RBBIMonkeyTest extends TestFmwk { boolean verbose = getBooleanProperty("verbose", false); int seed = getIntProperty("seed", 1); - List startedTests = new ArrayList(); + List startedTests = new ArrayList<>(); // Monkey testing is multi-threaded. // Each set of break rules to be tested is run in a separate thread. diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/CurrencyTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/CurrencyTest.java index 8a96666927..911306db9f 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/CurrencyTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/CurrencyTest.java @@ -25,8 +25,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.dev.test.TestUtil; -import com.ibm.icu.dev.test.TestUtil.JavaVendor; import com.ibm.icu.impl.CurrencyData; import com.ibm.icu.text.CurrencyDisplayNames; import com.ibm.icu.text.CurrencyMetaInfo; @@ -644,19 +642,18 @@ public class CurrencyTest extends TestFmwk { String[] actual = Currency.getAvailableCurrencyCodes(locale, date); // Order is not important as of 4.4. We never documented that it was. - Set expectedSet = new HashSet(); + Set expectedSet = new HashSet<>(); if (expected != null) { expectedSet.addAll(Arrays.asList(expected)); } - Set actualSet = new HashSet(); + Set actualSet = new HashSet<>(); if (actual != null) { actualSet.addAll(Arrays.asList(actual)); } assertEquals(locale + " on " + timeString, expectedSet, actualSet); // With Java Locale - // Note: skip this test on Java 6 or older when keywords are available - if (locale.getKeywords() == null || TestUtil.getJavaVendor() == JavaVendor.Android || TestUtil.getJavaVersion() >= 7) { + if (locale.getKeywords() == null) { Locale javaloc = locale.toLocale(); String[] actualWithJavaLocale = Currency.getAvailableCurrencyCodes(javaloc, date); // should be exactly same with the ULocale version @@ -739,7 +736,7 @@ public class CurrencyTest extends TestFmwk { String[] all = Currency.getKeywordValuesForLocale("currency", loc, false); // The items in the two collections should match (ignore order, // behavior change from 4.3.3) - Set returnedSet = new HashSet(); + Set returnedSet = new HashSet<>(); returnedSet.addAll(Arrays.asList(all)); assertEquals(loc.toString(), ALLSET, returnedSet); } diff --git a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/CollatorTest.java b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/CollatorTest.java index 01dd981252..2b7a2f23ac 100644 --- a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/CollatorTest.java +++ b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/CollatorTest.java @@ -140,16 +140,8 @@ public class CollatorTest extends TestFmwk { @Test public void TestCollationKeyword() { // ICU provider variant is appended - ULocale uloc0 = new ULocale("de_DE_" + TestUtil.ICU_VARIANT + "@collation=phonebook"); - Locale loc = uloc0.toLocale(); - // On Java 7+, locale extension is preserved - ULocale uloc = ULocale.forLocale(loc); - String nsType = uloc.getKeywordValue("collation"); - if (nsType == null) { - // Java 6 - skip this test - return; - } - + ULocale uloc = new ULocale("de_DE_" + TestUtil.ICU_VARIANT + "@collation=phonebook"); + Locale loc = uloc.toLocale(); Collator jdkColl = Collator.getInstance(loc); boolean isPhonebook = false; if (jdkColl instanceof CollatorICU) { diff --git a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatSymbolsTest.java b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatSymbolsTest.java index c403fd104b..c36159b671 100644 --- a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatSymbolsTest.java +++ b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatSymbolsTest.java @@ -192,16 +192,8 @@ public class DateFormatSymbolsTest extends TestFmwk { @Test public void TestCalendarKeyword() { // ICU provider variant is appended - ULocale uloc0 = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@calendar=japanese"); - Locale loc = uloc0.toLocale(); - // On Java 7+, locale extension is preserved - ULocale uloc = ULocale.forLocale(loc); - String calType = uloc.getKeywordValue("calendar"); - if (calType == null) { - // Java 6 - skip this test - return; - } - + ULocale uloc = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@calendar=japanese"); + Locale loc = uloc.toLocale(); DateFormatSymbols jdkDfs = DateFormatSymbols.getInstance(loc); com.ibm.icu.text.DateFormatSymbols icuDfs = com.ibm.icu.text.DateFormatSymbols.getInstance(uloc); diff --git a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatTest.java b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatTest.java index 02a668115d..b9cd2f81ee 100644 --- a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatTest.java +++ b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatTest.java @@ -205,16 +205,8 @@ public class DateFormatTest extends TestFmwk { @Test public void TestCalendarKeyword() { // ICU provider variant is appended - ULocale uloc0 = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@calendar=buddhist"); - Locale loc = uloc0.toLocale(); - // On Java 7+, locale extension is preserved - ULocale uloc = ULocale.forLocale(loc); - String calType = uloc.getKeywordValue("calendar"); - if (calType == null) { - // Java 6 - skip this test - return; - } - + ULocale uloc = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@calendar=buddhist"); + Locale loc = uloc.toLocale(); DateFormat jdkDfmt = DateFormat.getDateInstance(DateFormat.FULL, loc); Calendar cal = jdkDfmt.getCalendar(); boolean isBuddhist = false; diff --git a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DecimalFormatSymbolsTest.java b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DecimalFormatSymbolsTest.java index 526eb1c7e8..e5c1a712fa 100644 --- a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DecimalFormatSymbolsTest.java +++ b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DecimalFormatSymbolsTest.java @@ -167,16 +167,8 @@ public class DecimalFormatSymbolsTest extends TestFmwk { @Test public void TestKeywords() { // ICU provider variant is appended - ULocale uloc0 = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@numbers=Arab;currency=EUR"); - Locale loc = uloc0.toLocale(); - // On Java 7+, locale extension is preserved - ULocale uloc = ULocale.forLocale(loc); - String nsType = uloc.getKeywordValue("numbers"); - if (nsType == null) { - // Java 6 - skip this test - return; - } - + ULocale uloc = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@numbers=Arab;currency=EUR"); + Locale loc = uloc.toLocale(); DecimalFormatSymbols jdkDecfs = DecimalFormatSymbols.getInstance(loc); com.ibm.icu.text.DecimalFormatSymbols icuDecfs = com.ibm.icu.text.DecimalFormatSymbols.getInstance(uloc); // Check digit 0 diff --git a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/NumberFormatTest.java b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/NumberFormatTest.java index 6d4e2e1cc1..de3dbd48c7 100644 --- a/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/NumberFormatTest.java +++ b/icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/NumberFormatTest.java @@ -298,16 +298,8 @@ public class NumberFormatTest extends TestFmwk { @Test public void TestKeywords() { // ICU provider variant is appended - ULocale uloc0 = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@numbers=Arab;currency=EUR"); - Locale loc = uloc0.toLocale(); - // On Java 7+, locale extension is preserved - ULocale uloc = ULocale.forLocale(loc); - String nsType = uloc.getKeywordValue("numbers"); - if (nsType == null) { - // Java 6 - skip this test - return; - } - + ULocale uloc = new ULocale("en_US_" + TestUtil.ICU_VARIANT + "@numbers=arab;currency=EUR"); + Locale loc = uloc.toLocale(); NumberFormat jdkNfmt = NumberFormat.getCurrencyInstance(loc); com.ibm.icu.text.NumberFormat icuNfmt = com.ibm.icu.text.NumberFormat.getCurrencyInstance(uloc);