]> granicus.if.org Git - icu/commitdiff
ICU-13413 More clean-ups for code redundant/unnecessary for Java 7 and up
authorYoshito Umaoka <yumaoka@users.noreply.github.com>
Tue, 14 Aug 2018 00:12:53 +0000 (20:12 -0400)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:38 +0000 (14:27 -0700)
Simplified redundant code and removed unnecessary code path for Java 7 and later runtime in various places. Also cleaned up stale comments.

There is one test code change in com.ibm.icu.dev.test.localespi.NumberFormatTest - number keyword in test case was changed to Arab to arab. This test case was skipped with Java 6 runtime. It looks this code was note tested on Java 7 and later. @number=Arab does not work because it's case sensitive and must be all lower case letters.

24 files changed:
icu4j/main/classes/charset/src/com/ibm/icu/charset/UConverterDataReader.java
icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationSettings.java
icu4j/main/classes/collate/src/com/ibm/icu/text/RuleBasedCollator.java
icu4j/main/classes/core/src/com/ibm/icu/impl/ICUBinary.java
icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java
icu4j/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java
icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java
icu4j/main/classes/core/src/com/ibm/icu/impl/UPropertyAliases.java
icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java
icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java
icu4j/main/classes/localespi/src/com/ibm/icu/impl/icuadapter/TimeZoneJDK.java
icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/ICULocaleServiceProvider.java
icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/CurrencyNameProviderICU.java
icu4j/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/LocaleNameProviderICU.java
icu4j/main/shared/build/common-targets.xml
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDateFormatAPI.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBIMonkeyTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/CurrencyTest.java
icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/CollatorTest.java
icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatSymbolsTest.java
icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DateFormatTest.java
icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/DecimalFormatSymbolsTest.java
icu4j/main/tests/localespi/src/com/ibm/icu/dev/test/localespi/NumberFormatTest.java

index 842cb328e774388a04d48d5c05755013f879aa5c..457a5976687a61c0b52007cda218c49e8c913ecb 100644 (file)
@@ -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;
index 34865c017dd85af567c9db33823d88c71c51ae8e..4f7f40a7e508a811fa5f2c3873d0f42a4c6870f5 100644 (file)
@@ -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;
index bd4e833e5c938571d56fc9904208f73ec789a2a2..846c2e096f01661ca41b68be479f01a5d8de4a59 100644 (file)
@@ -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 {
index 98a1d0bb4e6ec060cbb712b7b2242efecea4ff22..76326bb075d51152491a255b5e6ed9726ec8a129 100644 (file)
@@ -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<DataFile> icuDataFiles = new ArrayList<DataFile>();
+    private static final List<DataFile> 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;
                 }
             }
index e4b30ecfe721be4f717e692a80c0e1d9d7d46082..5976f3518bdf7e2b2bd2ca6a20b06ad6f3014432 100644 (file)
@@ -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<Object>(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<Object>(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<Object>(item);
+                    values[index] = storeDirectly(size) ? item : new SoftReference<>(item);
                     return item;
                 } else /* not found && length == SIMPLE_LENGTH */ {
                     // Grow to become trie-like.
index a43d3f587dc5c3c499cef8c5d2ead9c0544ff83b..b078c78f43a96d7ffce2feb72448ebdc615ebc45 100644 (file)
@@ -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<String>();
+        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)
index 3d30dfa2df2c1a28700ed444291ad73321e717d4..1c4e890efaf45c610369bba9d20018d70a7c63aa 100644 (file)
@@ -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;
index 16e930c3d27567fb49fac82d2a52c212393d11a9..36bbfaef7cc1ae728059af29c7bca6ec08f64a07 100644 (file)
@@ -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;
index 9934dc7f31e3e5b29d1527a3cb6b2ea7bb5931f3..36c8d442931d75fdcd13b6b9dbed97c57c5fb589 100644 (file)
@@ -64,7 +64,7 @@ public class Currency extends MeasureUnit {
 
     // Cache to save currency name trie
     private static ICUCache<ULocale, List<TextTrieMap<CurrencyStringInfo>>> CURRENCY_NAME_CACHE =
-        new SimpleCache<ULocale, List<TextTrieMap<CurrencyStringInfo>>>();
+        new SimpleCache<>();
 
     /**
      * Selector for getName() indicating a symbolic name for a
@@ -229,7 +229,7 @@ public class Currency extends MeasureUnit {
     public static Set<Currency> getAvailableCurrencies() {
         CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
         List<String> list = info.currencies(CurrencyFilter.all());
-        HashSet<Currency> resultSet = new HashSet<Currency>(list.size());
+        HashSet<Currency> 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<TextTrieMap<CurrencyStringInfo>> currencyTrieVec = CURRENCY_NAME_CACHE.get(locale);
         if (currencyTrieVec == null) {
             TextTrieMap<CurrencyStringInfo> currencyNameTrie =
-                new TextTrieMap<CurrencyStringInfo>(true);
+                new TextTrieMap<>(true);
             TextTrieMap<CurrencyStringInfo> currencySymbolTrie =
-                new TextTrieMap<CurrencyStringInfo>(false);
-            currencyTrieVec = new ArrayList<TextTrieMap<CurrencyStringInfo>>();
+                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<List<String>>(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<String>(info.currencies(CurrencyFilter.all())));
-            ALL_CODES_AS_SET = new SoftReference<Set<String>>(all);
+                    new HashSet<>(info.currencies(CurrencyFilter.all())));
+            ALL_CODES_AS_SET = new SoftReference<>(all);
         }
         return all;
     }
index dc2352a9abdd2bda1b3ff67a16eeba621d16c14a..c7a2e8d545b57d465f9657cdbcc85cbcb60bdbd0 100644 (file)
@@ -541,7 +541,7 @@ abstract public class TimeZone implements Serializable, Cloneable, Freezable<Tim
             // Generic format
             TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(locale);
             long date = System.currentTimeMillis();
-            Output<TimeType> timeType = new Output<TimeType>(TimeType.UNKNOWN);
+            Output<TimeType> timeType = new Output<>(TimeType.UNKNOWN);
 
             switch (style) {
             case GENERIC_LOCATION:
@@ -673,7 +673,6 @@ abstract public class TimeZone implements Serializable, Cloneable, Freezable<Tim
      * @see #useDaylightTime
      * @stable ICU 49
      */
-    @SuppressWarnings("javadoc")    // java.util.TimeZone#observesDaylightTime() is introduced in Java 7
     public boolean observesDaylightTime() {
         return useDaylightTime() || inDaylightTime(new Date());
     }
index 301421fbe6e6ddddedaa7b9b41fdb58d8946739a..9104dea95505fa28504d59a44e36b43264067648 100644 (file)
@@ -8,8 +8,6 @@
  */
 package com.ibm.icu.impl.icuadapter;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
@@ -30,29 +28,18 @@ public class TimeZoneJDK extends com.ibm.icu.util.TimeZone {
 
     private TimeZone fJdkTz;
     private transient Calendar fJdkCal;
-    private static Method mObservesDaylightTime;
-
-    static {
-        try {
-            mObservesDaylightTime = TimeZone.class.getMethod("observesDaylightTime", (Class[]) null);
-        } catch (NoSuchMethodException e) {
-            // Java 6 or older
-        } catch (SecurityException e) {
-            // not visible
-        }
-    }
 
     private TimeZoneJDK(TimeZone jdkTz) {
         fJdkTz = (TimeZone)jdkTz.clone();
     }
-    
+
     public static com.ibm.icu.util.TimeZone wrap(TimeZone jdkTz) {
         if (jdkTz instanceof TimeZoneICU) {
             return ((TimeZoneICU)jdkTz).unwrap();
         }
         return new TimeZoneJDK(jdkTz);
     }
-    
+
     public TimeZone unwrap() {
         return (TimeZone)fJdkTz.clone();
     }
@@ -81,7 +68,7 @@ public class TimeZoneJDK extends com.ibm.icu.util.TimeZone {
     public String getDisplayName(boolean daylight, int style, Locale locale) {
         return fJdkTz.getDisplayName(daylight, style, locale);
     }
-    
+
     @Override
     public String getDisplayName(boolean daylight, int style, ULocale locale) {
         return fJdkTz.getDisplayName(daylight, style, locale.toLocale());
@@ -196,16 +183,7 @@ public class TimeZoneJDK extends com.ibm.icu.util.TimeZone {
 
     @Override
     public boolean observesDaylightTime() {
-        if (mObservesDaylightTime != null) {
-            // Java 7+
-            try {
-                return (Boolean)mObservesDaylightTime.invoke(fJdkTz, (Object[]) null);
-            } catch (IllegalAccessException e) {
-            } catch (IllegalArgumentException e) {
-            } catch (InvocationTargetException e) {
-            }
-        }
-        return super.observesDaylightTime();
+        return fJdkTz.observesDaylightTime();
     }
 
     // Freezable stuffs
index 3ee675dfc1aea8493f5d6e298ba7ced0ff376254..6c5e09115c2e956d642f637df0713b2b6626782f 100644 (file)
@@ -64,7 +64,7 @@ public class ICULocaleServiceProvider {
             return ULocale.forLocale(spLoc);
         }
 
-        // The locale may have script field on Java 7+.
+        // The locale may have script field.
         // So we once convert it to ULocale, then strip the ICU suffix off
         // if necessary.
         ULocale result = ULocale.forLocale(locale);
@@ -115,7 +115,7 @@ public class ICULocaleServiceProvider {
             return SPECIAL_LOCALES_MAP;
         }
 
-        Map<Locale, Locale> splocs = new HashMap<Locale, Locale>();
+        Map<Locale, Locale> 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<Locale> localeSet = new HashSet<Locale>();
+        Set<Locale> 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<Locale> 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()) {
index b359dbc84ee296756c69d2c1ef7aa5ede30ccb0b..8093b779d72a740da8b4b6d7904a5df8531adbcd 100644 (file)
@@ -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);
index d25854eae0a845162f87ab03910d024123760382..ffa447887046694054469110f11e64bb00051df6 100644 (file)
@@ -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))
index 56ea12c546bc0c51701d33a72812ac20c001f997..8ee10ed141f76f941b0efbbc8bea12a94d68a1dd 100644 (file)
@@ -25,7 +25,7 @@
 
     <target name="@compile">
         <echo message="build-local:     ${global.build-local.properties}"/>
-        <!-- set java 6 bootclasspath to empty if not set -->
+        <!-- set java 7 bootclasspath to empty if not set -->
         <property name="java7.bootclasspath" value=""/>
 
         <condition property="javac.bootclasspath" value="${java7.bootclasspath}" else="">
index 8e950686f772d2573fdf12ce52fddb2ff0cfa633..eb263df18b269e751f9fde78dfa67aec8302735a 100644 (file)
@@ -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]);
             }
         }
 
index 78845b3641c42692a6e4f82f27649d89d29e852e..2935a437cc4874ec7991d61e5ee40e9e3da6a412 100644 (file)
@@ -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))",
index 9ddb73bd0db02e8ee28c33e76c8090c9d4974e83..3637b688500f106ccd5b5b2b3a08c61d4ba5a309 100644 (file)
@@ -73,10 +73,10 @@ public class RBBIMonkeyTest extends TestFmwk {
     static class BreakRules {
         BreakRules(RBBIMonkeyImpl monkeyImpl) {
             fMonkeyImpl = monkeyImpl;
-            fBreakRules = new ArrayList<BreakRule>();
+            fBreakRules = new ArrayList<>();
             fType = BreakIterator.KIND_TITLE;
-            fCharClasses = new HashMap<String, CharClass>();
-            fCharClassList = new ArrayList<CharClass>();
+            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<RBBIMonkeyImpl> startedTests = new ArrayList<RBBIMonkeyImpl>();
+        List<RBBIMonkeyImpl> startedTests = new ArrayList<>();
 
         // Monkey testing is multi-threaded.
         // Each set of break rules to be tested is run in a separate thread.
index 8a966669273aa7c00b29960821f2f44971b6c9e8..911306db9f5a6f0081e6869d97e55e760de53b59 100644 (file)
@@ -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<String> expectedSet = new HashSet<String>();
+            Set<String> expectedSet = new HashSet<>();
             if (expected != null) {
                 expectedSet.addAll(Arrays.asList(expected));
             }
-            Set<String> actualSet = new HashSet<String>();
+            Set<String> 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<String> returnedSet = new HashSet<String>();
+            Set<String> returnedSet = new HashSet<>();
             returnedSet.addAll(Arrays.asList(all));
             assertEquals(loc.toString(), ALLSET, returnedSet);
         }
index 01dd9812524e421d13a8e6bfb13c584fc323d538..2b7a2f23ac45c15878fdb4f406372deb7f3b5a97 100644 (file)
@@ -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) {
index c403fd104bd4adff733523637ae7662001957d52..c36159b671f816b333c40940029f7bd975e8d159 100644 (file)
@@ -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);
 
index 02a668115d5aba1a0e738566808d8013d3fd120d..b9cd2f81eec34d710967953e72c5ffe80f8d8f2e 100644 (file)
@@ -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;
index 526eb1c7e8473e2deac0998f8e067755396dc376..e5c1a712fa726a11f1c7c91cfb2e63cad635eedd 100644 (file)
@@ -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
index 6d4e2e1cc11ae537a926ca5cc4f5d497fe5cec51..de3dbd48c7aff234e4f1f6d9dc19a1d77ff21e8b 100644 (file)
@@ -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);