]> granicus.if.org Git - icu/commitdiff
ICU-10836 Added missing Locale version APIs and test cases for various classes.
authorYoshito Umaoka <y.umaoka@gmail.com>
Mon, 23 Jun 2014 21:36:55 +0000 (21:36 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Mon, 23 Jun 2014 21:36:55 +0000 (21:36 +0000)
X-SVN-Rev: 35924

25 files changed:
icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java
icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyDisplayNames.java
icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java
icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java
icu4j/main/classes/core/src/com/ibm/icu/text/LocaleDisplayNames.java
icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/PluralRules.java
icu4j/main/classes/core/src/com/ibm/icu/text/RelativeDateTimeFormatter.java
icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java
icu4j/main/classes/core/src/com/ibm/icu/text/TimeZoneFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/TimeZoneNames.java
icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MeasureUnitTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRulesTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/RelativeDateTimeFormatterTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/text/SpoofCheckerTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/CurrencyTest.java
icu4j/main/tests/packaging/src/com/ibm/icu/dev/test/TestLocaleNamePackaging.java

index bde5a7747eef920ff1fb0187263ced66e1008dbd..ec8cd72304e9cdfa66335286d14641e96934992a 100644 (file)
@@ -5136,6 +5136,35 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
         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
index 390ffc9bc9ddb1127d107317a7eea28ffe4d24cc..86bb5f80d773f9f34e8c3f492953704603ec9a5c 100644 (file)
@@ -6,6 +6,7 @@
  */
 package com.ibm.icu.text;
 
+import java.util.Locale;
 import java.util.Map;
 
 import com.ibm.icu.impl.CurrencyData;
@@ -35,6 +36,23 @@ public abstract class CurrencyDisplayNames {
         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,
@@ -53,6 +71,25 @@ public abstract class CurrencyDisplayNames {
         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
index 83573394852eb08e1fc5fa930e35badc6ec99b34..8d15a5ed3c8376c60b6cf7d6ac1232b06552ef97 100644 (file)
@@ -12,6 +12,7 @@ import java.util.HashMap;
 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;
@@ -326,6 +327,19 @@ public class DateIntervalInfo implements Cloneable, Freezable<DateIntervalInfo>,
     }
 
 
+    /** 
+     * 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.
index 9602aeabf993dd526d36a23771880df22733369b..8bee2e64d73bb2990b9e54bfd4e60fba14b986a2 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Iterator;
 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;
@@ -86,6 +87,16 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
         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
index 369346f4bb0a9558e9d7f047bc8b3bd57082e7a9..2170c3a237e43b3186b5789e4ff476d2a2f46b7a 100644 (file)
@@ -53,6 +53,18 @@ public abstract class LocaleDisplayNames {
         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.
@@ -106,6 +118,20 @@ public abstract class LocaleDisplayNames {
         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
index 89036a88495484f7178509da0713e6e4f6a78690..c698e86e163b5ca9203d6bc9c4ee934dc3289097 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.EnumMap;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
 
@@ -223,6 +224,19 @@ public class MeasureFormat extends UFormat {
         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.
      *
@@ -265,6 +279,20 @@ public class MeasureFormat extends UFormat {
                 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&lt;? extends Measure&gt;, Measure[], and Measure
      * by delegating to formatMeasures.
@@ -468,6 +496,18 @@ public class MeasureFormat extends UFormat {
         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.
index 29781a86cd9bddd2451cd7f015deffc70810e847..8d80a4d4c1e57d5efe8ac00fd67ac6d3bb22cfb3 100644 (file)
@@ -11,6 +11,7 @@ import java.io.IOException;
 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;
@@ -199,6 +200,18 @@ public class PluralFormat extends UFormat {
         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.
@@ -224,6 +237,20 @@ public class PluralFormat extends UFormat {
         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.
@@ -236,6 +263,19 @@ public class PluralFormat extends UFormat {
         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
index 2f6c4e2fea42939a4580bcf518bbb11d383e61b3..2540d746d1b2699f4c96c816ce8955caa0d1d442 100644 (file)
@@ -1871,6 +1871,29 @@ public class PluralRules implements Serializable {
         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.
@@ -1893,6 +1916,29 @@ public class PluralRules implements Serializable {
         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.
      *
index 239e34545c4df36a47b498b624a2aa9c4ec00bd4..ced58a0a0a589fa7042587beaa7668725cbbcdf6 100644 (file)
@@ -7,6 +7,7 @@
 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;
@@ -310,6 +311,7 @@ public final class RelativeDateTimeFormatter {
      * 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.
      */
@@ -317,6 +319,18 @@ public final class RelativeDateTimeFormatter {
         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.
@@ -324,6 +338,7 @@ public final class RelativeDateTimeFormatter {
      * @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.
      */
@@ -368,6 +383,21 @@ public final class RelativeDateTimeFormatter {
                 
     }
            
+    /**
+     * 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"
@@ -436,7 +466,7 @@ public final class RelativeDateTimeFormatter {
     
     /**
      * 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.
      */
index 2fe4361ec81ed70718a8f9dffebec481db0b9ed4..c6819a2c97fa54530cbadbc88f58f96b6d016391 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Comparator;
 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;
@@ -573,6 +574,26 @@ public class SpoofChecker {
             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.
@@ -1450,6 +1471,22 @@ public class SpoofChecker {
         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
index 82c6e563a64ed7fc17d8c15b11e680d5949a610c..2219f756a8cf4010b400657b6d9f7f821411e966 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Date;
 import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.Set;
 
@@ -477,6 +478,21 @@ public class TimeZoneFormat extends UFormat implements Freezable<TimeZoneFormat>
         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.
      * 
index e16448a135e65f5bbca94f619ee0baafffa925b4..5aad466d7e32d6cc098052c05f6b2d0b0044c720 100644 (file)
@@ -10,6 +10,7 @@ import java.io.Serializable;
 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;
@@ -171,6 +172,19 @@ public abstract class TimeZoneNames implements Serializable {
         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.
index 2d66bcae9a17c3856651c799c94e524493092758..c5a0bccd98fa798564f13337ba966bc7e87e50b0 100644 (file)
@@ -194,6 +194,21 @@ public class Currency extends MeasureUnit {
         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
index 38d7c229a69920c169aba796df0d852cd76aa935..874d2e4c018738105e944843112a6ebdc29554f9 100644 (file)
@@ -1071,7 +1071,14 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
             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)
      */
index c059d79e085ebffc55214676a579b27ff3310502..a93194932c27c84ecbf92defdb4ee1b3bd5f305e 100644 (file)
@@ -15,6 +15,7 @@ import java.util.Iterator;
 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;
@@ -1327,43 +1328,53 @@ public class DateTimeGeneratorTest extends TestFmwk {
             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);
+    }
 }
index c4802c9d5f83db767664db212ccebabb479f7852..229a08828e3b0bb47639168b6db57297d3480aed 100644 (file)
@@ -335,12 +335,22 @@ public class MeasureUnitTest extends TestFmwk {
         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) {
@@ -718,7 +728,14 @@ public class MeasureUnitTest extends TestFmwk {
         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);
index 3f6e040e50b979d2a298fa69d0ef6f62dada0612..261b78acce506c8761289e1846e1dd7b2c00d975 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2007-2013, International Business Machines Corporation and
+ * Copyright (C) 2007-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
@@ -11,6 +11,7 @@ import java.text.ParsePosition;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -36,7 +37,7 @@ public class PluralFormatUnitTest extends TestFmwk {
 
     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);
@@ -52,6 +53,12 @@ public class PluralFormatUnitTest extends TestFmwk {
                 "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());
index 4335a56071a37f6527f7c17876436021b4b5bddd..8ba8dbcc9471ec82b679fb7230d98916758f8c4f 100644 (file)
@@ -23,6 +23,7 @@ import java.util.HashMap;
 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;
@@ -1091,4 +1092,14 @@ public class PluralRulesTest extends TestFmwk {
         }
         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);
+    }
 }
index e8d3d9ed09c3125cf8f0a9082db1b0c03879db18..e73fcb97c244b2d108f65756b8fec20d2160ebb0 100644 (file)
@@ -6,6 +6,8 @@
  */
 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;
@@ -713,7 +715,23 @@ public class RelativeDateTimeFormatterTest extends TestFmwk {
         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"),
index cfbb81a2d55e1cdb03d51febe49cf56b0fb6eeb7..e11a6207f9c934bc4209dae63a9e9c81b5e7b4d4 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Arrays;
 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;
@@ -772,9 +773,11 @@ public class TimeZoneFormatTest extends com.ibm.icu.dev.test.TestFmwk {
         };
 
         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]) {
@@ -782,6 +785,17 @@ public class TimeZoneFormatTest extends com.ibm.icu.dev.test.TestFmwk {
                         + ",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
index ecbb280df9a66e39a4ce32166cc1d73385af0000..c0d0ad2a19a735156ea1bb125dec41259085d976 100644 (file)
@@ -1,6 +1,6 @@
 /**
 *******************************************************************************
-* Copyright (C) 1996-2010, International Business Machines Corporation and
+* Copyright (C) 1996-2014, International Business Machines Corporation and
 * others. All Rights Reserved.
 *******************************************************************************
 */
@@ -358,6 +358,16 @@ public final class UCharacterCaseTest extends TestFmwk
                 "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",
index 488e50fc1f7de73c452212547caf67184386ca3c..18169b95175da45c103b4ea194d2d9cb8970b6d6 100644 (file)
@@ -2913,7 +2913,7 @@ public final class UCharacterTest extends TestFmwk
         
         // 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
index 2454ecf86406e1159b08506f6465e1f04b3118e8..7a8fb0bea5e4f6e18c3b2c01d1fc5ace2b90b278 100644 (file)
@@ -16,6 +16,7 @@ import java.util.BitSet;
 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;
@@ -218,22 +219,34 @@ public class SpoofCheckerTest extends TestFmwk {
      */
     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
index 6bfd090b00e416eb174595811fa48ce5e3253e6c..45a861039a135ce182348c01665fb6d31d9378f0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  **********************************************************************
- * Copyright (c) 2002-2013, International Business Machines
+ * Copyright (c) 2002-2014, International Business Machines
  * Corporation and others.  All Rights Reserved.
  **********************************************************************
  * Author: Alan Liu
@@ -19,6 +19,7 @@ import java.util.Locale;
 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;
@@ -239,7 +240,7 @@ public class CurrencyTest extends TestFmwk {
         // 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"));
@@ -261,6 +262,12 @@ public class CurrencyTest extends TestFmwk {
             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
@@ -565,6 +572,33 @@ public class CurrencyTest extends TestFmwk {
                 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);
+            }
         }
     }
 
index 7e27802a6d92ae939283c240f28a58b30224a678..42ad4d1422856968ee3fdea982b622165d0da4c7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2009-2012, International Business Machines Corporation and    *
+ * Copyright (C) 2009-2014, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -9,6 +9,8 @@ package com.ibm.icu.dev.test;
 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;
@@ -24,8 +26,8 @@ public class TestLocaleNamePackaging extends TestFmwk {
     }
 
     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;
     }
 
@@ -34,6 +36,12 @@ public class TestLocaleNamePackaging extends TestFmwk {
         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 = {
             "",
@@ -83,6 +91,20 @@ public class TestLocaleNamePackaging extends TestFmwk {
                 }
             }
         }
+
+        // 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() {
@@ -96,12 +118,12 @@ public class TestLocaleNamePackaging extends TestFmwk {
             "English",
             "Spanish",
             "German",
-            "Unknown or Invalid Language",
+            "Unknown Language",
             "",
             "ingl\u00E9s",
             "espa\u00F1ol",
             "alem\u00E1n",
-            "indeterminada",
+            "lengua desconocida",
             "",
             "Englisch",
             "Spanisch",
@@ -111,7 +133,7 @@ public class TestLocaleNamePackaging extends TestFmwk {
             "English",
             "Spanish",
             "German",
-            "Unknown or Invalid Language",
+            "Unknown Language",
         };
         String[] expectedWithoutLanguageData = {
             "",
@@ -134,16 +156,30 @@ public class TestLocaleNamePackaging extends TestFmwk {
                 }
             }
         }
+
+        // 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)",