return result.toString();
}
+ /**
+ * {@icu} <p>Returns the titlecase version of the argument string.</p>
+ * <p>Position for titlecasing is determined by the argument break
+ * iterator, hence the user can customize his break iterator for
+ * a specialized titlecasing. In this case only the forward iteration
+ * needs to be implemented.
+ * If the break iterator passed in is null, the default Unicode algorithm
+ * will be used to determine the titlecase positions.
+ * </p>
+ * <p>Only positions returned by the break iterator will be title cased,
+ * character in between the positions will all be in lower case.</p>
+ * <p>Casing is dependent on the argument locale and context-sensitive</p>
+ * @param locale which string is to be converted in
+ * @param str source string to be performed on
+ * @param titleIter break iterator to determine the positions in which
+ * the character should be title cased.
+ * @param options bit set to modify the titlecasing operation
+ * @return lowercase version of the argument string
+ * @see #TITLECASE_NO_LOWERCASE
+ * @see #TITLECASE_NO_BREAK_ADJUSTMENT
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static String toTitleCase(Locale locale, String str,
+ BreakIterator titleIter,
+ int options) {
+ return toTitleCase(ULocale.forLocale(locale), str, titleIter, options);
+ }
+
/**
* {@icu} The given character is mapped to its case folding equivalent according
* to UnicodeData.txt and CaseFolding.txt; if the character has no case
*/
package com.ibm.icu.text;
+import java.util.Locale;
import java.util.Map;
import com.ibm.icu.impl.CurrencyData;
return CurrencyData.provider.getInstance(locale, true);
}
+ /**
+ * Return an instance of CurrencyDisplayNames that provides information
+ * localized for display in the provided locale. If there is no data for the
+ * provided locale, this falls back to the current default locale; if there
+ * is no data for that either, it falls back to the root locale. Substitute
+ * values are returned from APIs when there is no data for the requested ISO
+ * code.
+ *
+ * @param locale the locale into which to localize the names
+ * @return a CurrencyDisplayNames
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static CurrencyDisplayNames getInstance(Locale locale) {
+ return getInstance(locale, true);
+ }
+
/**
* Return an instance of CurrencyDisplayNames that provides information
* localized for display in the provided locale. If noSubstitute is false,
return CurrencyData.provider.getInstance(locale, !noSubstitute);
}
+ /**
+ * Return an instance of CurrencyDisplayNames that provides information
+ * localized for display in the provided locale. If noSubstitute is false,
+ * this behaves like {@link #getInstance(Locale)}. Otherwise, 1) if there
+ * is no supporting data for the locale at all, there is no fallback through
+ * the default locale or root, and null is returned, and 2) if there is data
+ * for the locale, but not data for the requested ISO code, null is returned
+ * from those APIs instead of a substitute value.
+ *
+ * @param locale the JDK locale into which to localize the names
+ * @param noSubstitute if true, do not return substitute values.
+ * @return a CurrencyDisplayNames
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static CurrencyDisplayNames getInstance(Locale locale, boolean noSubstitute) {
+ return getInstance(ULocale.forLocale(locale), noSubstitute);
+ }
+
/**
* Returns true if currency display name data is available.
* @return true if currency display name data is available
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
}
+ /**
+ * Construct DateIntervalInfo for the given JDK locale,
+ * @param locale the interval patterns are loaded from the appropriate
+ * calendar data (specified calendar or default calendar)
+ * in this locale.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public DateIntervalInfo(Locale locale)
+ {
+ this(ULocale.forLocale(locale));
+ }
+
/*
* Initialize the DateIntervalInfo from locale
* @param locale the given locale.
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Set;
return getFrozenInstance(uLocale).cloneAsThawed();
}
+ /**
+ * Construct a flexible generator according to data for a given locale.
+ * @param locale The JDK locale to pass.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static DateTimePatternGenerator getInstance(Locale locale) {
+ return getInstance(ULocale.forLocale(locale));
+ }
+
/**
* Construct a frozen instance of DateTimePatternGenerator for a
* given locale. This method returns a cached frozen instance of
return getInstance(locale, DialectHandling.STANDARD_NAMES);
};
+ /**
+ * Convenience overload of {@link #getInstance(Locale, DisplayContext...)} that specifies
+ * {@link DisplayContext#STANDARD_NAMES}.
+ * @param locale the display JDK locale
+ * @return a LocaleDisplayNames instance
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static LocaleDisplayNames getInstance(Locale locale) {
+ return getInstance(ULocale.forLocale(locale));
+ };
+
/**
* Returns an instance of LocaleDisplayNames that returns names formatted for the provided locale,
* using the provided dialectHandling.
return result;
}
+ /**
+ * Returns an instance of LocaleDisplayNames that returns names formatted for the provided JDK
+ * locale, using the provided DisplayContext settings
+ * @param locale the display JDK locale
+ * @param contexts one or more context settings (e.g. for dialect
+ * handling, capitalization, etc.
+ * @return a LocaleDisplayNames instance
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static LocaleDisplayNames getInstance(Locale locale, DisplayContext... contexts) {
+ return getInstance(ULocale.forLocale(locale), contexts);
+ }
+
// getters for state
/**
* Returns the locale used to determine the display names. This is not necessarily the same
import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
return getInstance(locale, formatWidth, NumberFormat.getInstance(locale));
}
+ /**
+ * Create a format from the JDK locale, formatWidth, and format.
+ *
+ * @param locale the JDK locale.
+ * @param formatWidth hints how long formatted strings should be.
+ * @return The new MeasureFormat object.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static MeasureFormat getInstance(Locale locale, FormatWidth formatWidth) {
+ return getInstance(ULocale.forLocale(locale), formatWidth);
+ }
+
/**
* Create a format from the locale, formatWidth, and format.
*
new ImmutableNumberFormat(intFormat));
}
+ /**
+ * Create a format from the JDK locale, formatWidth, and format.
+ *
+ * @param locale the JDK locale.
+ * @param formatWidth hints how long formatted strings should be.
+ * @param format This is defensively copied.
+ * @return The new MeasureFormat object.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static MeasureFormat getInstance(Locale locale, FormatWidth formatWidth, NumberFormat format) {
+ return getInstance(ULocale.forLocale(locale), formatWidth, format);
+ }
+
/**
* Able to format Collection<? extends Measure>, Measure[], and Measure
* by delegating to formatMeasures.
return new CurrencyFormat(locale);
}
+ /**
+ * Return a formatter for CurrencyAmount objects in the given
+ * JDK locale.
+ * @param locale desired JDK locale
+ * @return a formatter object
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static MeasureFormat getCurrencyFormat(Locale locale) {
+ return getCurrencyFormat(ULocale.forLocale(locale));
+ }
+
/**
* Return a formatter for CurrencyAmount objects in the default
* <code>FORMAT</code> locale.
import java.io.ObjectInputStream;
import java.text.FieldPosition;
import java.text.ParsePosition;
+import java.util.Locale;
import java.util.Map;
import com.ibm.icu.impl.Utility;
init(null, PluralType.CARDINAL, ulocale);
}
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given JDK locale.
+ * @param locale the <code>PluralFormat</code> will be configured with
+ * rules for this locale. This locale will also be used for standard
+ * number formatting.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public PluralFormat(Locale locale) {
+ this(ULocale.forLocale(locale));
+ }
+
/**
* Creates a new cardinal-number <code>PluralFormat</code> for a given set of rules.
* The standard number formatting will be done using the default <code>FORMAT</code> locale.
init(rules, PluralType.CARDINAL, ulocale);
}
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given set of rules.
+ * The standard number formatting will be done using the given locale.
+ * @param locale the default number formatting will be done using this
+ * locale.
+ * @param rules defines the behavior of the <code>PluralFormat</code>
+ * object.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public PluralFormat(Locale locale, PluralRules rules) {
+ this(ULocale.forLocale(locale), rules);
+ }
+
/**
* Creates a new <code>PluralFormat</code> for the plural type.
* The standard number formatting will be done using the given locale.
init(null, type, ulocale);
}
+ /**
+ * Creates a new <code>PluralFormat</code> for the plural type.
+ * The standard number formatting will be done using the given JDK locale.
+ * @param locale the default number formatting will be done using this
+ * locale.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public PluralFormat(Locale locale, PluralType type) {
+ this(ULocale.forLocale(locale), type);
+ }
+
/**
* Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string.
* The default <code>FORMAT</code> locale will be used to get the set of plural rules and for
return Factory.getDefaultFactory().forLocale(locale, PluralType.CARDINAL);
}
+ /**
+ * Provides access to the predefined cardinal-number <code>PluralRules</code> for a given
+ * JDK locale.
+ * Same as forLocale(locale, PluralType.CARDINAL).
+ *
+ * <p>ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>.
+ * For these predefined rules, see CLDR page at
+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+ *
+ * @param locale The JDK locale for which a <code>PluralRules</code> object is
+ * returned.
+ * @return The predefined <code>PluralRules</code> object for this locale.
+ * If there's no predefined rules for this locale, the rules
+ * for the closest parent in the locale hierarchy that has one will
+ * be returned. The final fallback always returns the default
+ * rules.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static PluralRules forLocale(Locale locale) {
+ return forLocale(ULocale.forLocale(locale));
+ }
+
/**
* Provides access to the predefined <code>PluralRules</code> for a given
* locale and the plural type.
return Factory.getDefaultFactory().forLocale(locale, type);
}
+ /**
+ * Provides access to the predefined <code>PluralRules</code> for a given
+ * JDK locale and the plural type.
+ *
+ * <p>ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>.
+ * For these predefined rules, see CLDR page at
+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+ *
+ * @param locale The JDK locale for which a <code>PluralRules</code> object is
+ * returned.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @return The predefined <code>PluralRules</code> object for this locale.
+ * If there's no predefined rules for this locale, the rules
+ * for the closest parent in the locale hierarchy that has one will
+ * be returned. The final fallback always returns the default
+ * rules.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static PluralRules forLocale(Locale locale, PluralType type) {
+ return forLocale(ULocale.forLocale(locale), type);
+ }
+
/*
* Checks whether a token is a valid keyword.
*
package com.ibm.icu.text;
import java.util.EnumMap;
+import java.util.Locale;
import com.ibm.icu.impl.CalendarData;
import com.ibm.icu.impl.ICUCache;
* Returns a RelativeDateTimeFormatter for a particular locale.
*
* @param locale the locale.
+ * @return An instance of RelativeDateTimeFormatter.
* @draft ICU 53
* @provisional This API might change or be removed in a future release.
*/
return getInstance(locale, null, Style.LONG, DisplayContext.CAPITALIZATION_NONE);
}
+ /**
+ * Returns a RelativeDateTimeFormatter for a particular JDK locale.
+ *
+ * @param locale the JDK locale.
+ * @return An instance of RelativeDateTimeFormatter.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static RelativeDateTimeFormatter getInstance(Locale locale) {
+ return getInstance(ULocale.forLocale(locale));
+ }
+
/**
* Returns a RelativeDateTimeFormatter for a particular locale that uses a particular
* NumberFormat object.
* @param locale the locale
* @param nf the number format object. It is defensively copied to ensure thread-safety
* and immutability of this class.
+ * @return An instance of RelativeDateTimeFormatter.
* @draft ICU 53
* @provisional This API might change or be removed in a future release.
*/
}
+ /**
+ * Returns a RelativeDateTimeFormatter for a particular JDK locale that uses a particular
+ * NumberFormat object.
+ *
+ * @param locale the JDK locale
+ * @param nf the number format object. It is defensively copied to ensure thread-safety
+ * and immutability of this class.
+ * @return An instance of RelativeDateTimeFormatter.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static RelativeDateTimeFormatter getInstance(Locale locale, NumberFormat nf) {
+ return getInstance(ULocale.forLocale(locale), nf);
+ }
+
/**
* Formats a relative date with a quantity such as "in 5 days" or
* "3 months ago"
/**
* Returns a copy of the NumberFormat this object is using.
- *
+ * @return A copy of the NumberFormat.
* @draft ICU 53
* @provisional This API might change or be removed in a future release.
*/
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashSet;
+import java.util.Locale;
import java.util.Set;
import java.util.Vector;
import java.util.regex.Matcher;
return this;
}
+ /**
+ * Limit characters that are acceptable in identifiers being checked to those normally used with the languages
+ * associated with the specified locales. Any previously specified list of locales is replaced by the new
+ * settings.
+ * @param locales
+ * A Set of Locales, from which the language and associated script are extracted. If the locales Set
+ * is null, no restrictions will be placed on the allowed characters.
+ *
+ * @return self
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public Builder setAllowedJavaLocales(Set<Locale> locales) {
+ HashSet<ULocale> ulocales = new HashSet<ULocale>(locales.size());
+ for (Locale locale : locales) {
+ ulocales.add(ULocale.forLocale(locale));
+ }
+ return setAllowedLocales(ulocales);
+ }
+
// Add (union) to the UnicodeSet all of the characters for the scripts
// used for the specified locale. Part of the implementation of
// setAllowedLocales.
return fAllowedLocales;
}
+ /**
+ * Get a list of JDK locales for the scripts that are acceptable in strings to be checked. If no limitations on scripts
+ * have been specified, an empty set will be returned.
+ *
+ * @return A set of locales corresponding to the acceptable scripts.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public Set<Locale> getAllowedJavaLocales() {
+ HashSet<Locale> locales = new HashSet<Locale>(fAllowedLocales.size());
+ for (ULocale uloc : fAllowedLocales) {
+ locales.add(uloc.toLocale());
+ }
+ return locales;
+ }
+
/**
* Get a UnicodeSet for the characters permitted in an identifier. This corresponds to the limits imposed by the Set
* Allowed Characters functions. Limitations imposed by other checks will not be reflected in the set returned by
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Set;
return _tzfCache.getInstance(locale, locale);
}
+ /**
+ * Returns a frozen instance of <code>TimeZoneFormat</code> for the given JDK locale.
+ * <p><b>Note</b>: The instance returned by this method is frozen. If you want to
+ * customize a TimeZoneFormat, you must use {@link #cloneAsThawed()} to get a
+ * thawed copy first.
+ *
+ * @param locale the JDK locale.
+ * @return a frozen instance of <code>TimeZoneFormat</code> for the given locale.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static TimeZoneFormat getInstance(Locale locale) {
+ return getInstance(ULocale.forLocale(locale));
+ }
+
/**
* Returns the time zone display name data used by this instance.
*
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
+import java.util.Locale;
import java.util.Set;
import com.ibm.icu.impl.ICUConfig;
return TZNAMES_CACHE.getInstance(key, locale);
}
+ /**
+ * Returns an instance of <code>TimeZoneDisplayNames</code> for the specified JDK locale.
+ *
+ * @param locale
+ * The JDK locale.
+ * @return An instance of <code>TimeZoneDisplayNames</code>
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static TimeZoneNames getInstance(Locale locale) {
+ return getInstance(ULocale.forLocale(locale));
+ }
+
/**
* Returns an immutable set of all available meta zone IDs.
* @return An immutable set of all available meta zone IDs.
return list.toArray(new String[list.size()]);
}
+ /**
+ * Returns an array of Strings which contain the currency
+ * identifiers that are valid for the given JDK locale on the
+ * given date. If there are no such identifiers, returns null.
+ * Returned identifiers are in preference order.
+ * @param loc the JDK locale for which to retrieve currency codes.
+ * @param d the date for which to retrieve currency codes for the given locale.
+ * @return The array of ISO currency codes.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static String[] getAvailableCurrencyCodes(Locale loc, Date d) {
+ return getAvailableCurrencyCodes(ULocale.forLocale(loc), d);
+ }
+
/**
* Returns the set of available currencies. The returned set of currencies contains all of the
* available currencies, including obsolete ones. The result set can be modified without
errln("FAIL: Exception - " + e.getClass().getName());
}
}
-
+
+ public void TestConstructor() {
+ DateIntervalInfo diiJapan = new DateIntervalInfo(ULocale.JAPAN);
+ DateIntervalInfo diiJapanJ = new DateIntervalInfo(Locale.JAPAN);
+
+ assertEquals("DateIntervalInfo constructors", diiJapan, diiJapanJ);
+ }
+
/* Tests the method
* public boolean equals(Object a)
*/
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
ULocale uloc = new ULocale(localeName);
DateTimePatternGenerator dtpgen = DateTimePatternGenerator.getInstance(uloc);
for (AllFieldsTestItem testItem: testItems) {
- char[] skelBuf = new char[FIELD_LENGTH_MAX];
- for (int chrIndx = 0; chrIndx < FIELD_LENGTH_MAX; chrIndx++) {
- skelBuf[chrIndx] = testItem.patternChar;
- }
- for (int lenIndx = 0; lenIndx < testItem.fieldLengths.length; lenIndx++) {
- int skelLen = testItem.fieldLengths[lenIndx];
- if (skelLen > FIELD_LENGTH_MAX) {
- continue;
- };
- String skeleton = new String(skelBuf, 0, skelLen);
- String pattern = dtpgen.getBestPattern(skeleton);
- if (pattern.length() <= 0) {
+ char[] skelBuf = new char[FIELD_LENGTH_MAX];
+ for (int chrIndx = 0; chrIndx < FIELD_LENGTH_MAX; chrIndx++) {
+ skelBuf[chrIndx] = testItem.patternChar;
+ }
+ for (int lenIndx = 0; lenIndx < testItem.fieldLengths.length; lenIndx++) {
+ int skelLen = testItem.fieldLengths[lenIndx];
+ if (skelLen > FIELD_LENGTH_MAX) {
+ continue;
+ };
+ String skeleton = new String(skelBuf, 0, skelLen);
+ String pattern = dtpgen.getBestPattern(skeleton);
+ if (pattern.length() <= 0) {
errln("DateTimePatternGenerator getBestPattern for locale " + localeName +
", skeleton " + skeleton + ", produces 0-length pattern");
- } else {
- // test that resulting pattern has at least one char in mustIncludeOneOf
- boolean inQuoted = false;
- int patIndx, patLen = pattern.length();
- for (patIndx = 0; patIndx < patLen; patIndx++) {
- char c = pattern.charAt(patIndx);
- if (c == '\'') {
- inQuoted = !inQuoted;
- } else if (!inQuoted && c <= 'z' && c >= 'A') {
- if (testItem.mustIncludeOneOf.indexOf(c) >= 0) {
- break;
- }
- }
- }
- if (patIndx >= patLen) {
+ } else {
+ // test that resulting pattern has at least one char in mustIncludeOneOf
+ boolean inQuoted = false;
+ int patIndx, patLen = pattern.length();
+ for (patIndx = 0; patIndx < patLen; patIndx++) {
+ char c = pattern.charAt(patIndx);
+ if (c == '\'') {
+ inQuoted = !inQuoted;
+ } else if (!inQuoted && c <= 'z' && c >= 'A') {
+ if (testItem.mustIncludeOneOf.indexOf(c) >= 0) {
+ break;
+ }
+ }
+ }
+ if (patIndx >= patLen) {
errln("DateTimePatternGenerator getBestPattern for locale " + localeName +
", skeleton " + skeleton +
", produces pattern without required chars: " + pattern);
- }
- }
- }
+ }
+ }
+ }
}
}
}
+ public void TestJavaLocale() {
+ DateTimePatternGenerator genUloc = DateTimePatternGenerator.getInstance(ULocale.GERMANY);
+ DateTimePatternGenerator genLoc = DateTimePatternGenerator.getInstance(Locale.GERMANY);
+
+ final String pat = "yMdHms";
+ String patUloc = genUloc.getBestPattern(pat);
+ String patLoc = genLoc.getBestPattern(pat);
+
+ assertEquals("German pattern 'yMdHms' - getInstance with Java Locale", patUloc, patLoc);
+ }
}
verifyFormatPeriod("en NARROW", mf, narrowData);
mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.NUMERIC, nf);
verifyFormatPeriod("en NUMERIC", mf, numericData);
+
nf = NumberFormat.getNumberInstance(ULocale.GERMAN);
nf.setMaximumFractionDigits(4);
mf = MeasureFormat.getInstance(ULocale.GERMAN, FormatWidth.WIDE, nf);
verifyFormatPeriod("de FULL", mf, fullDataDe);
mf = MeasureFormat.getInstance(ULocale.GERMAN, FormatWidth.NUMERIC, nf);
verifyFormatPeriod("de NUMERIC", mf, numericDataDe);
+
+ // Same tests, with Java Locale
+ nf = NumberFormat.getNumberInstance(Locale.GERMAN);
+ nf.setMaximumFractionDigits(4);
+ mf = MeasureFormat.getInstance(Locale.GERMAN, FormatWidth.WIDE, nf);
+ verifyFormatPeriod("de FULL(Java Locale)", mf, fullDataDe);
+ mf = MeasureFormat.getInstance(Locale.GERMAN, FormatWidth.NUMERIC, nf);
+ verifyFormatPeriod("de NUMERIC(Java Locale)", mf, numericDataDe);
+
}
private void verifyFormatPeriod(String desc, MeasureFormat mf, Object[][] testData) {
assertEquals("getNumberFormat", ULocale.ENGLISH, mf.getNumberFormat().getLocale(ULocale.VALID_LOCALE));
assertEquals("getWidth", MeasureFormat.FormatWidth.WIDE, mf.getWidth());
}
-
+
+ public void testCurrencyFormatLocale() {
+ MeasureFormat mfu = MeasureFormat.getCurrencyFormat(ULocale.FRANCE);
+ MeasureFormat mfj = MeasureFormat.getCurrencyFormat(Locale.FRANCE);
+
+ assertEquals("getCurrencyFormat ULocale/Locale", mfu, mfj);
+ }
+
public void testDoubleZero() {
ULocale en = new ULocale("en");
NumberFormat nf = NumberFormat.getInstance(en);
/*
*******************************************************************************
- * Copyright (C) 2007-2013, International Business Machines Corporation and
+ * Copyright (C) 2007-2014, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
public void TestConstructor() {
// Test correct formatting of numbers.
- PluralFormat plFmts[] = new PluralFormat[8];
+ PluralFormat plFmts[] = new PluralFormat[10];
plFmts[0] = new PluralFormat();
plFmts[0].applyPattern("other{#}");
plFmts[1] = new PluralFormat(PluralRules.DEFAULT);
"other{#}");
plFmts[7] = new PluralFormat(ULocale.getDefault(), "other{#}");
+ // Constructors with Java Locale
+ plFmts[8] = new PluralFormat(Locale.getDefault());
+ plFmts[8].applyPattern("other{#}");
+ plFmts[9] = new PluralFormat(Locale.getDefault(), PluralRules.DEFAULT);
+ plFmts[9].applyPattern("other{#}");
+
// These plural formats should produce the same output as a
// NumberFormat for the default locale.
NumberFormat numberFmt = NumberFormat.getInstance(ULocale.getDefault());
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
}
return b.append(']').toString();
}
+
+ public void testJavaLocaleFactory() {
+ PluralRules rulesU0 = PluralRules.forLocale(ULocale.FRANCE);
+ PluralRules rulesJ0 = PluralRules.forLocale(Locale.FRANCE);
+ assertEquals("forLocale()", rulesU0, rulesJ0);
+
+ PluralRules rulesU1 = PluralRules.forLocale(ULocale.FRANCE, PluralType.ORDINAL);
+ PluralRules rulesJ1 = PluralRules.forLocale(Locale.FRANCE, PluralType.ORDINAL);
+ assertEquals("forLocale() with type", rulesU1, rulesJ1);
+ }
}
*/
package com.ibm.icu.dev.test.format;
+import java.util.Locale;
+
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.text.DisplayContext;
import com.ibm.icu.text.NumberFormat;
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"));
assertEquals("TestcombineDateAndTime", "yesterday, 3:50", fmt.combineDateAndTime("yesterday", "3:50"));
}
-
+
+ public void TestJavaLocale() {
+ Locale loc = Locale.US;
+ double amount = 12.3456d;
+
+ RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(loc);
+ String s = fmt.format(amount, Direction.LAST, RelativeUnit.SECONDS);
+ assertEquals("Java Locale.US", "12.346 seconds ago", s);
+
+ // Modified instance
+ NumberFormat nf = fmt.getNumberFormat();
+ nf.setMaximumFractionDigits(1);
+ fmt = RelativeDateTimeFormatter.getInstance(loc, nf);
+
+ s = fmt.format(amount, Direction.LAST, RelativeUnit.SECONDS);
+ assertEquals("Java Locale.US", "12.3 seconds ago", s);
+ }
public void TestGetters() {
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(
new ULocale("en_US"),
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
};
for (Object[] testCase : TESTDATA) {
- TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(new ULocale((String)testCase[0]));
TimeZone tz = TimeZone.getTimeZone((String)testCase[1]);
Output<TimeType> timeType = new Output<TimeType>();
+
+ ULocale uloc = new ULocale((String)testCase[0]);
+ TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(uloc);
String out = tzfmt.format((Style)testCase[3], tz, ((Date)testCase[2]).getTime(), timeType);
if (!out.equals((String)testCase[4]) || timeType.value != testCase[5]) {
+ ",style=" + testCase[3] + "]: expected [output=" + testCase[4] + ",type=" + testCase[5]
+ "]; actual [output=" + out + ",type=" + timeType.value + "]");
}
+
+ // with equivalent Java Locale
+ Locale loc = uloc.toLocale();
+ tzfmt = TimeZoneFormat.getInstance(loc);
+ out = tzfmt.format((Style)testCase[3], tz, ((Date)testCase[2]).getTime(), timeType);
+
+ if (!out.equals((String)testCase[4]) || timeType.value != testCase[5]) {
+ errln("Format result for [locale(Java)=" + testCase[0] + ",tzid=" + testCase[1] + ",date=" + testCase[2]
+ + ",style=" + testCase[3] + "]: expected [output=" + testCase[4] + ",type=" + testCase[5]
+ + "]; actual [output=" + out + ",type=" + timeType.value + "]");
+ }
}
}
}
\ No newline at end of file
/**
*******************************************************************************
-* Copyright (C) 1996-2010, International Business Machines Corporation and
+* Copyright (C) 1996-2014, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
"IJssel Igloo IJmuiden",
UCharacter.toTitleCase(LOC_DUTCH, "ijssel igloo IJMUIDEN", null));
+ // Also check the behavior using Java Locale
+ Locale JAVALOC_DUTCH = new Locale("nl");
+ assertEquals("Dutch titlecase check in English (Java Locale)",
+ "Ijssel Igloo Ijmuiden",
+ UCharacter.toTitleCase(Locale.ENGLISH, "ijssel igloo IJMUIDEN", null));
+
+ assertEquals("Dutch titlecase check in Dutch (Java Locale)",
+ "IJssel Igloo IJmuiden",
+ UCharacter.toTitleCase(JAVALOC_DUTCH, "ijssel igloo IJMUIDEN", null));
+
iter.setText("ijssel igloo IjMUIdEN iPoD ijenough");
assertEquals("Dutch titlecase check in Dutch with nolowercase option",
"IJssel Igloo IJMUIdEN IPoD IJenough",
// Calls the function "String toTitleCase(ULocale locale, String str, BreakIterator titleIter, int options)"
// Tests when "if (locale == null)" is true
- UCharacter.toTitleCase(null, "", null, 0);
+ UCharacter.toTitleCase((ULocale)null, "", null, 0);
// TODO: Tests when "if(index==BreakIterator.DONE || index>srcLength)" is true
// TODO: Tests when "while((c=iter.nextCaseMapCP())>=0 && UCaseProps.NONE==gCsp.getType(c))" is false
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.Locale;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
*/
public void TestAllowedLocales() {
SpoofChecker sc = new SpoofChecker.Builder().build();
- Set<ULocale> allowedLocales = new LinkedHashSet<ULocale>();
+ Set<ULocale> allowedLocales = null;
+ Set<Locale> allowedJavaLocales = null;
boolean checkResults;
/* Default allowed locales list should be empty */
allowedLocales = sc.getAllowedLocales();
- assertTrue("", allowedLocales.isEmpty());
+ assertTrue("Empty allowed locales", allowedLocales.isEmpty());
+
+ allowedJavaLocales = sc.getAllowedJavaLocales();
+ assertTrue("Empty allowed Java locales", allowedJavaLocales.isEmpty());
/* Allow en and ru, which should enable Latin and Cyrillic only to pass */
ULocale enloc = new ULocale("en");
ULocale ruloc = new ULocale("ru_RU");
+ allowedLocales = new HashSet<ULocale>();
allowedLocales.add(enloc);
allowedLocales.add(ruloc);
sc = new SpoofChecker.Builder().setAllowedLocales(allowedLocales).build();
allowedLocales = sc.getAllowedLocales();
- assertTrue("", allowedLocales.contains(enloc));
- assertTrue("", allowedLocales.contains(ruloc));
+ assertTrue("en in allowed locales", allowedLocales.contains(enloc));
+ assertTrue("ru_RU in allowed locales", allowedLocales.contains(ruloc));
+
+ Locale frlocJ = new Locale("fr");
+ allowedJavaLocales = new HashSet<Locale>();
+ allowedJavaLocales.add(frlocJ);
+ sc = new SpoofChecker.Builder().setAllowedJavaLocales(allowedJavaLocales).build();
+ assertFalse("no en in allowed Java locales", allowedJavaLocales.contains(new Locale("en")));
+ assertTrue("fr in allowed Java locales", allowedJavaLocales.contains(frlocJ));
/*
* Limit checks to SpoofChecker.CHAR_LIMIT. Some of the test data has whole script confusables also, which we
/*
**********************************************************************
- * Copyright (c) 2002-2013, International Business Machines
+ * Copyright (c) 2002-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
import java.util.Set;
import com.ibm.icu.dev.test.TestFmwk;
+import com.ibm.icu.dev.test.TestUtil;
import com.ibm.icu.impl.CurrencyData;
import com.ibm.icu.text.CurrencyDisplayNames;
import com.ibm.icu.text.CurrencyMetaInfo;
// with no substitute
cdn = CurrencyDisplayNames.getInstance(ULocale.GERMANY, true);
assertNotNull("have currency data for Germany", cdn);
-
+
// known currency, behavior unchanged
assertEquals("de_USD_name", "US-Dollar", cdn.getName("USD"));
assertEquals("de_USD_symbol", "$", cdn.getSymbol("USD"));
ln = " (" + cdn.getULocale().toString() + ")";
}
assertNull("no fallback from unknown locale" + ln , cdn);
+
+ // Locale version
+ cdn = CurrencyDisplayNames.getInstance(Locale.GERMANY, true);
+ assertNotNull("have currency data for Germany (Java Locale)", cdn);
+ assertEquals("de_USD_name (Locale)", "US-Dollar", cdn.getName("USD"));
+ assertNull("de_FOO_name (Locale)", cdn.getName("FOO"));
}
// Coverage-only test of CurrencyData
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.getJavaVersion() >= 7) {
+ Locale javaloc = locale.toLocale();
+ String[] actualWithJavaLocale = Currency.getAvailableCurrencyCodes(javaloc, date);
+ // should be exactly same with the ULocale version
+ boolean same = true;
+ if (actual == null) {
+ if (actualWithJavaLocale != null) {
+ same = false;
+ }
+ } else {
+ if (actualWithJavaLocale == null || actual.length != actualWithJavaLocale.length) {
+ same = false;
+ } else {
+ same = true;
+ for (int i = 0; i < actual.length; i++) {
+ if (!actual[i].equals(actualWithJavaLocale[i])) {
+ same = false;
+ break;
+ }
+ }
+ }
+ }
+ assertTrue("getAvailableCurrencyCodes with ULocale vs Locale", same);
+ }
}
}
/*
*******************************************************************************
- * Copyright (C) 2009-2012, International Business Machines Corporation and *
+ * Copyright (C) 2009-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
import static com.ibm.icu.impl.LocaleDisplayNamesImpl.DataTableType.LANG;
import static com.ibm.icu.impl.LocaleDisplayNamesImpl.DataTableType.REGION;
+import java.util.Locale;
+
import com.ibm.icu.impl.LocaleDisplayNamesImpl;
import com.ibm.icu.text.LocaleDisplayNames;
import com.ibm.icu.text.LocaleDisplayNames.DialectHandling;
}
public boolean validate() {
- warnln("language data: " + LocaleDisplayNamesImpl.haveData(LANG));
- warnln(" region data: " + LocaleDisplayNamesImpl.haveData(REGION));
+ logln("language data: " + LocaleDisplayNamesImpl.haveData(LANG));
+ logln(" region data: " + LocaleDisplayNamesImpl.haveData(REGION));
return true;
}
new ULocale("und_TH")
};
+ // Java Locales equivalent to above
+ private static Locale[] javaLocales = {
+ new Locale(""), Locale.US, new Locale("es", "ES"), Locale.GERMANY,
+ new Locale("und", "TH")
+ };
+
public void testRegionDisplayNames() {
String[] expectedWithRegionData = {
"",
}
}
}
+
+ // Same test with Java Locale
+ n = 0;
+ for (Locale displayJavaLocale : javaLocales) {
+ LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayJavaLocale);
+ for (Locale targetLocale : javaLocales) {
+ String result = dn.regionDisplayName(targetLocale.getCountry());
+ assertEquals(targetLocale + " in " + displayJavaLocale, expected[n++], result);
+ if (n == expected.length) {
+ n = 0;
+ }
+ }
+ }
+
}
public void testLanguageDisplayNames() {
"English",
"Spanish",
"German",
- "Unknown or Invalid Language",
+ "Unknown Language",
"",
"ingl\u00E9s",
"espa\u00F1ol",
"alem\u00E1n",
- "indeterminada",
+ "lengua desconocida",
"",
"Englisch",
"Spanisch",
"English",
"Spanish",
"German",
- "Unknown or Invalid Language",
+ "Unknown Language",
};
String[] expectedWithoutLanguageData = {
"",
}
}
}
+
+ // Same test with Java Locale
+ n = 0;
+ for (Locale displayJavaLocale : javaLocales) {
+ LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayJavaLocale);
+ for (Locale targetLocale : javaLocales) {
+ String result = dn.languageDisplayName(targetLocale.getLanguage());
+ assertEquals(targetLocale + " in " + displayJavaLocale, expected[n++], result);
+ if (n == expected.length) {
+ n = 0;
+ }
+ }
+ }
+
}
// test a 'root' locale, with keywords
public void testLocaleDisplayNameWithKeywords() {
String[] expectedWithLanguageData = {
"root (collation=phonebook)",
- "Root (collation=Phonebook Sort Order)",
- "ra\u00EDz (intercalaci\u00F3n=orden de list\u00EDn telef\u00F3nico)",
- "Root (Sortierung=Telefonbuch-Sortierregeln)",
- "Root (collation=Phonebook Sort Order)",
+ "Root (Phonebook Sort Order)",
+ "ra\u00EDz (orden de list\u00EDn telef\u00F3nico)",
+ "Root (Telefonbuch-Sortierung)",
+ "Root (Phonebook Sort Order)",
};
String[] expectedWithoutLanguageData = {
"root (collation=phonebook)",