ICU-13413 More clean-ups for code redundant/unnecessary for Java 7 and up
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.
This commit is contained in:
parent
18789823b2
commit
a4fc56f382
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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="">
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))",
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user