From 2ae8b0560225e982db0aee303f3b75f2874491f7 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka <y.umaoka@gmail.com> Date: Thu, 11 Aug 2011 19:53:36 +0000 Subject: [PATCH] ICU-8630 Category locale support for Java 7 conformance. X-SVN-Rev: 30487 --- .../src/com/ibm/icu/text/Collator.java | 11 +- .../core/src/com/ibm/icu/impl/ICUService.java | 7 +- .../icu/text/ChineseDateFormatSymbols.java | 8 +- .../com/ibm/icu/text/CurrencyPluralInfo.java | 8 +- .../core/src/com/ibm/icu/text/DateFormat.java | 41 ++- .../com/ibm/icu/text/DateFormatSymbols.java | 6 +- .../com/ibm/icu/text/DateIntervalFormat.java | 17 +- .../icu/text/DateTimePatternGenerator.java | 6 +- .../src/com/ibm/icu/text/DecimalFormat.java | 11 +- .../ibm/icu/text/DecimalFormatSymbols.java | 6 +- .../src/com/ibm/icu/text/MeasureFormat.java | 8 +- .../src/com/ibm/icu/text/MessageFormat.java | 6 +- .../src/com/ibm/icu/text/NumberFormat.java | 38 +- .../src/com/ibm/icu/text/NumberingSystem.java | 8 +- .../src/com/ibm/icu/text/PluralFormat.java | 14 +- .../ibm/icu/text/RuleBasedNumberFormat.java | 30 +- .../com/ibm/icu/text/SimpleDateFormat.java | 15 +- .../src/com/ibm/icu/text/TimeUnitFormat.java | 5 +- .../core/src/com/ibm/icu/util/CECalendar.java | 24 +- .../core/src/com/ibm/icu/util/Calendar.java | 8 +- .../src/com/ibm/icu/util/ChineseCalendar.java | 32 +- .../core/src/com/ibm/icu/util/Currency.java | 6 +- .../com/ibm/icu/util/GregorianCalendar.java | 29 +- .../src/com/ibm/icu/util/HebrewCalendar.java | 28 +- .../core/src/com/ibm/icu/util/Holiday.java | 11 +- .../src/com/ibm/icu/util/IndianCalendar.java | 27 +- .../src/com/ibm/icu/util/IslamicCalendar.java | 26 +- .../core/src/com/ibm/icu/util/LocaleData.java | 8 +- .../core/src/com/ibm/icu/util/TimeZone.java | 11 +- .../core/src/com/ibm/icu/util/ULocale.java | 329 +++++++++++++++--- .../src/com/ibm/icu/text/Transliterator.java | 6 +- .../ibm/icu/dev/test/util/ULocaleTest.java | 60 ++++ 32 files changed, 617 insertions(+), 233 deletions(-) diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java b/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java index e4ccbbaec00..7e87e63ff2b 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java @@ -22,6 +22,7 @@ import com.ibm.icu.util.Freezable; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.VersionInfo; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.Collator}.{@icu _usage_} @@ -871,24 +872,26 @@ public abstract class Collator implements Comparator<Object>, Freezable<Collator /** * {@icu} Returns the name of the collator for the objectLocale, localized for the - * current locale. + * default <code>DISPLAY</code> locale. * @param objectLocale the locale of the collator * @return the display name + * @see com.ibm.icu.util.ULocale.Category#DISPLAY * @stable ICU 2.6 */ static public String getDisplayName(Locale objectLocale) { - return getShim().getDisplayName(ULocale.forLocale(objectLocale), ULocale.getDefault()); + return getShim().getDisplayName(ULocale.forLocale(objectLocale), ULocale.getDefault(Category.DISPLAY)); } /** * {@icu} Returns the name of the collator for the objectLocale, localized for the - * current locale. + * default <code>DISPLAY</code> locale. * @param objectLocale the locale of the collator * @return the display name + * @see com.ibm.icu.util.ULocale.Category#DISPLAY * @stable ICU 3.2 */ static public String getDisplayName(ULocale objectLocale) { - return getShim().getDisplayName(objectLocale, ULocale.getDefault()); + return getShim().getDisplayName(objectLocale, ULocale.getDefault(Category.DISPLAY)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java index cbd8c676ed5..486a06bfe31 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2010, International Business Machines Corporation and * + * Copyright (C) 2001-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -23,6 +23,7 @@ import java.util.SortedMap; import java.util.TreeMap; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * <p>A Service provides access to service objects that implement a @@ -625,7 +626,7 @@ public class ICUService extends ICUNotifier { * uses the current default locale. */ public String getDisplayName(String id) { - return getDisplayName(id, ULocale.getDefault()); + return getDisplayName(id, ULocale.getDefault(Category.DISPLAY)); } /** @@ -657,7 +658,7 @@ public class ICUService extends ICUNotifier { * the comparator, and null for the matchID. */ public SortedMap<String, String> getDisplayNames() { - ULocale locale = ULocale.getDefault(); + ULocale locale = ULocale.getDefault(Category.DISPLAY); return getDisplayNames(locale, null, null); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java index 8e8599b372b..b5b075d3ecc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2000-2010, International Business Machines Corporation and + * Copyright (C) 2000-2011, International Business Machines Corporation and * others. All Rights Reserved. **************************************************************************** */ @@ -12,6 +12,7 @@ import com.ibm.icu.impl.CalendarData; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.ChineseCalendar; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * A subclass of {@link DateFormatSymbols} for {@link ChineseDateFormat}. @@ -34,11 +35,12 @@ public class ChineseDateFormatSymbols extends DateFormatSymbols { String isLeapMonth[]; // Do NOT add =null initializer /** - * Construct a ChineseDateFormatSymbols for the default locale. + * Construct a ChineseDateFormatSymbols for the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 2.0 */ public ChineseDateFormatSymbols() { - this(ULocale.getDefault()); + this(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java b/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java index 5a36064dd2a..6586190800e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2009-2010, International Business Machines Corporation and * + * Copyright (C) 2009-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -14,6 +14,7 @@ import java.util.Map; import com.ibm.icu.impl.CurrencyData; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * This class represents the information needed by @@ -37,11 +38,12 @@ public class CurrencyPluralInfo implements Cloneable, Serializable { private static final long serialVersionUID = 1; /** - * Create a CurrencyPluralInfo object for the default locale. + * Create a CurrencyPluralInfo object for the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 4.2 */ public CurrencyPluralInfo() { - initialize(ULocale.getDefault()); + initialize(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java index 536e4e1337e..f29c81aa073 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java @@ -22,6 +22,7 @@ import com.ibm.icu.util.Calendar; import com.ibm.icu.util.GregorianCalendar; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.DateFormat}.{@icu _usage_} @@ -907,26 +908,28 @@ public abstract class DateFormat extends UFormat { /** * Gets the time formatter with the default formatting style - * for the default locale. + * for the default <code>FORMAT</code> locale. * @return a time formatter. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static DateFormat getTimeInstance() { - return get(-1, DEFAULT, ULocale.getDefault()); + return get(-1, DEFAULT, ULocale.getDefault(Category.FORMAT)); } /** * Returns the time formatter with the given formatting style - * for the default locale. + * for the default <code>FORMAT</code> locale. * @param style the given formatting style. For example, * SHORT for "h:mm a" in the US locale. * @return a time formatter. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static DateFormat getTimeInstance(int style) { - return get(-1, style, ULocale.getDefault()); + return get(-1, style, ULocale.getDefault(Category.FORMAT)); } /** @@ -961,26 +964,28 @@ public abstract class DateFormat extends UFormat { /** * Returns the date formatter with the default formatting style - * for the default locale. + * for the default <code>FORMAT</code> locale. * @return a date formatter. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static DateFormat getDateInstance() { - return get(DEFAULT, -1, ULocale.getDefault()); + return get(DEFAULT, -1, ULocale.getDefault(Category.FORMAT)); } /** * Returns the date formatter with the given formatting style - * for the default locale. + * for the default <code>FORMAT</code> locale. * @param style the given formatting style. For example, * SHORT for "M/d/yy" in the US locale. * @return a date formatter. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static DateFormat getDateInstance(int style) { - return get(style, -1, ULocale.getDefault()); + return get(style, -1, ULocale.getDefault(Category.FORMAT)); } /** @@ -1015,29 +1020,31 @@ public abstract class DateFormat extends UFormat { /** * Returns the date/time formatter with the default formatting style - * for the default locale. + * for the default <code>FORMAT</code> locale. * @return a date/time formatter. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static DateFormat getDateTimeInstance() { - return get(DEFAULT, DEFAULT, ULocale.getDefault()); + return get(DEFAULT, DEFAULT, ULocale.getDefault(Category.FORMAT)); } /** * Returns the date/time formatter with the given date and time - * formatting styles for the default locale. + * formatting styles for the default <code>FORMAT</code> locale. * @param dateStyle the given date formatting style. For example, * SHORT for "M/d/yy" in the US locale. * @param timeStyle the given time formatting style. For example, * SHORT for "h:mm a" in the US locale. * @return a date/time formatter. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle) { - return get(dateStyle, timeStyle, ULocale.getDefault()); + return get(dateStyle, timeStyle, ULocale.getDefault(Category.FORMAT)); } /** @@ -1434,7 +1441,7 @@ public abstract class DateFormat extends UFormat { * @stable ICU 2.0 */ static final public DateFormat getInstance(Calendar cal) { - return getInstance(cal, ULocale.getDefault()); + return getInstance(cal, ULocale.getDefault(Category.FORMAT)); } /** @@ -1442,7 +1449,7 @@ public abstract class DateFormat extends UFormat { * @stable ICU 2.0 */ static final public DateFormat getDateInstance(Calendar cal, int dateStyle) { - return getDateInstance(cal, dateStyle, ULocale.getDefault()); + return getDateInstance(cal, dateStyle, ULocale.getDefault(Category.FORMAT)); } /** @@ -1450,7 +1457,7 @@ public abstract class DateFormat extends UFormat { * @stable ICU 2.0 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) { - return getTimeInstance(cal, timeStyle, ULocale.getDefault()); + return getTimeInstance(cal, timeStyle, ULocale.getDefault(Category.FORMAT)); } /** @@ -1458,7 +1465,7 @@ public abstract class DateFormat extends UFormat { * @stable ICU 2.0 */ static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, int timeStyle) { - return getDateTimeInstance(cal, dateStyle, timeStyle, ULocale.getDefault()); + return getDateTimeInstance(cal, dateStyle, timeStyle, ULocale.getDefault(Category.FORMAT)); } /** @@ -1466,7 +1473,7 @@ public abstract class DateFormat extends UFormat { * @stable ICU 4.0 */ public final static DateFormat getPatternInstance(String pattern) { - return getPatternInstance(pattern, ULocale.getDefault()); + return getPatternInstance(pattern, ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java index 94e4b32e950..30845c51370 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java @@ -25,6 +25,7 @@ import com.ibm.icu.util.Calendar; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.DateFormatSymbols}.{@icu _usage_} @@ -126,15 +127,16 @@ public class DateFormatSymbols implements Serializable, Cloneable { /** * Constructs a DateFormatSymbols object by loading format data from - * resources for the default locale. + * resources for the default <code>FORMAT</code> locale. * * @throws java.util.MissingResourceException if the resources for the default locale * cannot be found or cannot be loaded. + * @see Category#FORMAT * @stable ICU 2.0 */ public DateFormatSymbols() { - this(ULocale.getDefault()); + this(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java index 572ecdb57f0..8acefc5c1f1 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java @@ -1,5 +1,5 @@ /* -* Copyright (C) 2008-2010, International Business Machines +* Copyright (C) 2008-2011, International Business Machines * Corporation and others. All Rights Reserved. */ @@ -21,6 +21,7 @@ import com.ibm.icu.text.DateIntervalInfo.PatternInfo; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.DateInterval; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** @@ -348,21 +349,22 @@ public class DateIntervalFormat extends UFormat { /** - * Construct a DateIntervalFormat from skeleton and the default locale. + * Construct a DateIntervalFormat from skeleton and the default <code>FORMAT</code> locale. * * This is a convenient override of * getInstance(String skeleton, ULocale locale) - * with the value of locale as default locale. + * with the value of locale as default <code>FORMAT</code> locale. * * @param skeleton the skeleton on which interval format based. * @return a date time interval formatter. + * @see Category#FORMAT * @stable ICU 4.0 */ public static final DateIntervalFormat getInstance(String skeleton) { - return getInstance(skeleton, ULocale.getDefault()); + return getInstance(skeleton, ULocale.getDefault(Category.FORMAT)); } @@ -424,21 +426,22 @@ public class DateIntervalFormat extends UFormat { /** * Construct a DateIntervalFormat from skeleton - * DateIntervalInfo, and default locale. + * DateIntervalInfo, and the default <code>FORMAT</code> locale. * * This is a convenient override of * getInstance(String skeleton, ULocale locale, DateIntervalInfo dtitvinf) - * with the locale value as default locale. + * with the locale value as default <code>FORMAT</code> locale. * * @param skeleton the skeleton on which interval format based. * @param dtitvinf the DateIntervalInfo object to be adopted. * @return a date time interval formatter. + * @see Category#FORMAT * @stable ICU 4.0 */ public static final DateIntervalFormat getInstance(String skeleton, DateIntervalInfo dtitvinf) { - return getInstance(skeleton, ULocale.getDefault(), dtitvinf); + return getInstance(skeleton, ULocale.getDefault(Category.FORMAT), dtitvinf); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java index 287f6f371d2..3cf27bade0b 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java @@ -29,6 +29,7 @@ import com.ibm.icu.util.Calendar; import com.ibm.icu.util.Freezable; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.ULocale.Category; /** * This class provides flexible generation of date format patterns, like @@ -105,11 +106,12 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera } /** - * Construct a flexible generator according to data for the default locale. + * Construct a flexible generator according to data for the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 3.6 */ public static DateTimePatternGenerator getInstance() { - return getInstance(ULocale.getDefault()); + return getInstance(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java index 659a208247c..4a41229e1be 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java @@ -31,6 +31,7 @@ import com.ibm.icu.math.MathContext; import com.ibm.icu.util.Currency; import com.ibm.icu.util.CurrencyAmount; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.DecimalFormat}.{@icu _usage_} @@ -601,7 +602,7 @@ public class DecimalFormat extends NumberFormat { /** * Creates a DecimalFormat using the default pattern and symbols for the default - * locale. This is a convenient way to obtain a DecimalFormat when + * <code>FORMAT</code> locale. This is a convenient way to obtain a DecimalFormat when * internationalization is not the main concern. * * <p>To obtain standard formats for a given locale, use the factory methods on @@ -612,10 +613,11 @@ public class DecimalFormat extends NumberFormat { * @see NumberFormat#getNumberInstance * @see NumberFormat#getCurrencyInstance * @see NumberFormat#getPercentInstance + * @see Category#FORMAT * @stable ICU 2.0 */ public DecimalFormat() { - ULocale def = ULocale.getDefault(); + ULocale def = ULocale.getDefault(Category.FORMAT); String pattern = getPattern(def, 0); // Always applyPattern after the symbols are set this.symbols = new DecimalFormatSymbols(def); @@ -632,7 +634,7 @@ public class DecimalFormat extends NumberFormat { /** * Creates a DecimalFormat from the given pattern and the symbols for the default - * locale. This is a convenient way to obtain a DecimalFormat when + * <code>FORMAT</code> locale. This is a convenient way to obtain a DecimalFormat when * internationalization is not the main concern. * * <p>To obtain standard formats for a given locale, use the factory methods on @@ -645,11 +647,12 @@ public class DecimalFormat extends NumberFormat { * @see NumberFormat#getNumberInstance * @see NumberFormat#getCurrencyInstance * @see NumberFormat#getPercentInstance + * @see Category#FORMAT * @stable ICU 2.0 */ public DecimalFormat(String pattern) { // Always applyPattern after the symbols are set - ULocale def = ULocale.getDefault(); + ULocale def = ULocale.getDefault(Category.FORMAT); this.symbols = new DecimalFormatSymbols(def); setCurrency(Currency.getInstance(def)); applyPatternWithoutExpandAffix(pattern, false); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java index fcc6fe36005..b416bfa3eb5 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java @@ -24,6 +24,7 @@ import com.ibm.icu.impl.SimpleCache; import com.ibm.icu.util.Currency; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.DecimalFormatSymbols}.{@icu _usage_} @@ -43,11 +44,12 @@ import com.ibm.icu.util.UResourceBundle; */ public class DecimalFormatSymbols implements Cloneable, Serializable { /** - * Creates a DecimalFormatSymbols object for the default locale. + * Creates a DecimalFormatSymbols object for the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 2.0 */ public DecimalFormatSymbols() { - initialize(ULocale.getDefault()); + initialize(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java index 247454682d9..035265776ef 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (c) 2004-2007, International Business Machines +* Copyright (c) 2004-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu @@ -11,6 +11,7 @@ package com.ibm.icu.text; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * A formatter for Measure objects. This is an abstract base class. @@ -46,11 +47,12 @@ public abstract class MeasureFormat extends UFormat { /** * Return a formatter for CurrencyAmount objects in the default - * locale. + * <code>FORMAT</code> locale. * @return a formatter object + * @see Category#FORMAT * @stable ICU 3.0 */ public static MeasureFormat getCurrencyFormat() { - return getCurrencyFormat(ULocale.getDefault()); + return getCurrencyFormat(ULocale.getDefault(Category.FORMAT)); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java index 74398171912..ba6d42dbf9c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java @@ -37,6 +37,7 @@ import com.ibm.icu.impl.Utility; import com.ibm.icu.text.MessagePattern.ArgType; import com.ibm.icu.text.MessagePattern.Part; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.MessageFormat}.{@icu _usage_} @@ -328,16 +329,17 @@ public class MessageFormat extends UFormat { static final long serialVersionUID = 7136212545847378652L; /** - * Constructs a MessageFormat for the default locale and the + * Constructs a MessageFormat for the default <code>FORMAT</code> locale and the * specified pattern. * Sets the locale and calls applyPattern(pattern). * * @param pattern the pattern for this message format * @exception IllegalArgumentException if the pattern is invalid + * @see Category#FORMAT * @stable ICU 3.0 */ public MessageFormat(String pattern) { - this.ulocale = ULocale.getDefault(); + this.ulocale = ULocale.getDefault(Category.FORMAT); applyPattern(pattern); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormat.java index ac08416c98c..62fbee40943 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormat.java @@ -26,6 +26,7 @@ import com.ibm.icu.util.Currency; import com.ibm.icu.util.CurrencyAmount; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.text.NumberFormat}.{@icu _usage_} @@ -497,16 +498,17 @@ public abstract class NumberFormat extends UFormat { //============== Locale Stuff ===================== /** - * Returns the default number format for the current default locale. + * Returns the default number format for the current default <code>FORMAT</code> locale. * The default format is one of the styles provided by the other * factory methods: getNumberInstance, getIntegerInstance, * getCurrencyInstance or getPercentInstance. * Exactly which one is locale-dependent. + * @see Category#FORMAT * @stable ICU 2.0 */ //Bug 4408066 [Richard/GCL] public final static NumberFormat getInstance() { - return getInstance(ULocale.getDefault(), NUMBERSTYLE); + return getInstance(ULocale.getDefault(Category.FORMAT), NUMBERSTYLE); } /** @@ -532,12 +534,13 @@ public abstract class NumberFormat extends UFormat { } /** - * {@icu} Returns a specific style number format for default locale. + * {@icu} Returns a specific style number format for default <code>FORMAT</code> locale. * @param style number format style + * @see Category#FORMAT * @stable ICU 4.2 */ public final static NumberFormat getInstance(int style) { - return getInstance(ULocale.getDefault(), style); + return getInstance(ULocale.getDefault(Category.FORMAT), style); } /** @@ -552,11 +555,12 @@ public abstract class NumberFormat extends UFormat { /** - * Returns a general-purpose number format for the current default locale. + * Returns a general-purpose number format for the current default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 2.0 */ public final static NumberFormat getNumberInstance() { - return getInstance(ULocale.getDefault(), NUMBERSTYLE); + return getInstance(ULocale.getDefault(Category.FORMAT), NUMBERSTYLE); } /** @@ -576,7 +580,7 @@ public abstract class NumberFormat extends UFormat { } /** - * Returns an integer number format for the current default locale. The + * Returns an integer number format for the current default <code>FORMAT</code> locale. The * returned number format is configured to round floating point numbers * to the nearest integer using IEEE half-even rounding (see {@link * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting, @@ -584,11 +588,12 @@ public abstract class NumberFormat extends UFormat { * #isParseIntegerOnly isParseIntegerOnly}). * * @return a number format for integer values + * @see Category#FORMAT * @stable ICU 2.0 */ //Bug 4408066 [Richard/GCL] public final static NumberFormat getIntegerInstance() { - return getInstance(ULocale.getDefault(), INTEGERSTYLE); + return getInstance(ULocale.getDefault(Category.FORMAT), INTEGERSTYLE); } /** @@ -625,12 +630,13 @@ public abstract class NumberFormat extends UFormat { } /** - * Returns a currency format for the current default locale. + * Returns a currency format for the current default <code>FORMAT</code> locale. * @return a number format for currency + * @see Category#FORMAT * @stable ICU 2.0 */ public final static NumberFormat getCurrencyInstance() { - return getInstance(ULocale.getDefault(), CURRENCYSTYLE); + return getInstance(ULocale.getDefault(Category.FORMAT), CURRENCYSTYLE); } /** @@ -652,12 +658,13 @@ public abstract class NumberFormat extends UFormat { } /** - * Returns a percentage format for the current default locale. + * Returns a percentage format for the current default <code>FORMAT</code> locale. * @return a number format for percents + * @see Category#FORMAT * @stable ICU 2.0 */ public final static NumberFormat getPercentInstance() { - return getInstance(ULocale.getDefault(), PERCENTSTYLE); + return getInstance(ULocale.getDefault(Category.FORMAT), PERCENTSTYLE); } /** @@ -679,12 +686,13 @@ public abstract class NumberFormat extends UFormat { } /** - * {@icu} Returns a scientific format for the current default locale. + * {@icu} Returns a scientific format for the current default <code>FORMAT</code> locale. * @return a scientific number format + * @see Category#FORMAT * @stable ICU 2.0 */ public final static NumberFormat getScientificInstance() { - return getInstance(ULocale.getDefault(), SCIENTIFICSTYLE); + return getInstance(ULocale.getDefault(Category.FORMAT), SCIENTIFICSTYLE); } /** @@ -1196,7 +1204,7 @@ public abstract class NumberFormat extends UFormat { if (c == null) { ULocale uloc = getLocale(ULocale.VALID_LOCALE); if (uloc == null) { - uloc = ULocale.getDefault(); + uloc = ULocale.getDefault(Category.FORMAT); } c = Currency.getInstance(uloc); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/NumberingSystem.java b/icu4j/main/classes/core/src/com/ibm/icu/text/NumberingSystem.java index c0760608c37..13e87288ca4 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/NumberingSystem.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/NumberingSystem.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2009-2010, International Business Machines Corporation and * + * Copyright (C) 2009-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -18,6 +18,7 @@ import com.ibm.icu.lang.UCharacter; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.UResourceBundleIterator; +import com.ibm.icu.util.ULocale.Category; /** @@ -153,11 +154,12 @@ public class NumberingSystem { } /** - * Returns the default numbering system for the default locale. + * Returns the default numbering system for the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 4.2 */ public static NumberingSystem getInstance() { - return getInstance(ULocale.getDefault()); + return getInstance(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java index 5efd38f5a41..11977d7ffd9 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java @@ -15,6 +15,7 @@ import java.util.Map; import com.ibm.icu.impl.Utility; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** * <p> @@ -181,7 +182,7 @@ public class PluralFormat extends UFormat { * @stable ICU 3.8 */ public PluralFormat() { - init(null, ULocale.getDefault()); + init(null, ULocale.getDefault(Category.FORMAT)); } /** @@ -203,7 +204,7 @@ public class PluralFormat extends UFormat { * @stable ICU 3.8 */ public PluralFormat(PluralRules rules) { - init(rules, ULocale.getDefault()); + init(rules, ULocale.getDefault(Category.FORMAT)); } /** @@ -228,7 +229,7 @@ public class PluralFormat extends UFormat { * @stable ICU 3.8 */ public PluralFormat(String pattern) { - init(null, ULocale.getDefault()); + init(null, ULocale.getDefault(Category.FORMAT)); applyPattern(pattern); } @@ -260,7 +261,7 @@ public class PluralFormat extends UFormat { * @stable ICU 3.8 */ public PluralFormat(PluralRules rules, String pattern) { - init(rules, ULocale.getDefault()); + init(rules, ULocale.getDefault(Category.FORMAT)); applyPattern(pattern); } @@ -588,12 +589,13 @@ public class PluralFormat extends UFormat { * constructed from {@link #PluralFormat(ULocale)}. * @param ulocale the <code>ULocale</code> used to configure the * formatter. If <code>ulocale</code> is <code>null</code>, the - * default locale will be used. + * default <code>FORMAT</code> locale will be used. + * @see Category#FORMAT * @stable ICU 3.8 */ public void setLocale(ULocale ulocale) { if (ulocale == null) { - ulocale = ULocale.getDefault(); + ulocale = ULocale.getDefault(Category.FORMAT); } init(null, ulocale); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java index 2db8196a4c4..970124ba128 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java @@ -23,6 +23,7 @@ import com.ibm.icu.impl.PatternProps; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.UResourceBundleIterator; +import com.ibm.icu.util.ULocale.Category; /** @@ -607,20 +608,21 @@ public class RuleBasedNumberFormat extends NumberFormat { /** * Creates a RuleBasedNumberFormat that behaves according to the description - * passed in. The formatter uses the default locale. + * passed in. The formatter uses the default <code>FORMAT</code> locale. * @param description A description of the formatter's desired behavior. * See the class documentation for a complete explanation of the description * syntax. + * @see Category#FORMAT * @stable ICU 2.0 */ public RuleBasedNumberFormat(String description) { - locale = ULocale.getDefault(); + locale = ULocale.getDefault(Category.FORMAT); init(description, null); } /** * Creates a RuleBasedNumberFormat that behaves according to the description - * passed in. The formatter uses the default locale. + * passed in. The formatter uses the default <code>FORMAT</code> locale. * <p> * The localizations data provides information about the public * rule sets and their localized display names for different @@ -637,10 +639,11 @@ public class RuleBasedNumberFormat extends NumberFormat { * syntax. * @param localizations a list of localizations for the rule set * names in the description. + * @see Category#FORMAT * @stable ICU 3.2 */ public RuleBasedNumberFormat(String description, String[][] localizations) { - locale = ULocale.getDefault(); + locale = ULocale.getDefault(Category.FORMAT); init(description, localizations); } @@ -805,17 +808,18 @@ public class RuleBasedNumberFormat extends NumberFormat { /** * Creates a RuleBasedNumberFormat from a predefined description. Uses the - * default locale. + * default <code>FORMAT</code> locale. * @param format A selector code specifying which kind of formatter to create. * There are three legal values: SPELLOUT, which creates a formatter that spells * out a value in words in the default locale's langyage, ORDINAL, which attaches * an ordinal suffix from the default locale's language to a numeral, and * DURATION, which formats a duration in seconds as hours, minutes, and seconds. * or NUMBERING_SYSTEM, which is used for alternate numbering systems such as Hebrew. + * @see Category#FORMAT * @stable ICU 2.0 */ public RuleBasedNumberFormat(int format) { - this(ULocale.getDefault(), format); + this(ULocale.getDefault(Category.FORMAT), format); } //----------------------------------------------------------------------- @@ -911,7 +915,7 @@ public class RuleBasedNumberFormat extends NumberFormat { try { loc = (ULocale) in.readObject(); } catch (Exception e) { - loc = ULocale.getDefault(); + loc = ULocale.getDefault(Category.FORMAT); } // build a brand-new RuleBasedNumberFormat from the description, @@ -963,7 +967,7 @@ public class RuleBasedNumberFormat extends NumberFormat { private String[] getNameListForLocale(ULocale loc) { if (loc != null && ruleSetDisplayNames != null) { - String[] localeNames = { loc.getBaseName(), ULocale.getDefault().getBaseName() }; + String[] localeNames = { loc.getBaseName(), ULocale.getDefault(Category.DISPLAY).getBaseName() }; for (int i = 0; i < localeNames.length; ++i) { String lname = localeNames[i]; while (lname.length() > 0) { @@ -1001,13 +1005,14 @@ public class RuleBasedNumberFormat extends NumberFormat { } /** - * Return the rule set display names for the current default locale. + * Return the rule set display names for the current default <code>DISPLAY</code> locale. * @return an array of the display names * @see #getRuleSetDisplayNames(ULocale) + * @see Category#DISPLAY * @stable ICU 3.2 */ public String[] getRuleSetDisplayNames() { - return getRuleSetDisplayNames(ULocale.getDefault()); + return getRuleSetDisplayNames(ULocale.getDefault(Category.DISPLAY)); } /** @@ -1034,13 +1039,14 @@ public class RuleBasedNumberFormat extends NumberFormat { } /** - * Return the rule set display name for the provided rule set in the current default locale. + * Return the rule set display name for the provided rule set in the current default <code>DISPLAY</code> locale. * @return the display name for the rule set * @see #getRuleSetDisplayName(String,ULocale) + * @see Category#DISPLAY * @stable ICU 3.2 */ public String getRuleSetDisplayName(String ruleSetName) { - return getRuleSetDisplayName(ruleSetName, ULocale.getDefault()); + return getRuleSetDisplayName(ruleSetName, ULocale.getDefault(Category.DISPLAY)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java index 57d62ca5b53..e64aaedf0be 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java @@ -37,6 +37,7 @@ import com.ibm.icu.util.Output; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.TimeZoneTransition; import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.ULocale.Category; /** @@ -367,11 +368,12 @@ public class SimpleDateFormat extends DateFormat { private volatile TimeZoneFormat tzFormat; /** - * Constructs a SimpleDateFormat using the default pattern for the default + * Constructs a SimpleDateFormat using the default pattern for the default <code>FORMAT</code> * locale. <b>Note:</b> Not all locales support SimpleDateFormat; for full * generality, use the factory methods in the DateFormat class. * * @see DateFormat + * @see Category#FORMAT * @stable ICU 2.0 */ public SimpleDateFormat() { @@ -379,9 +381,10 @@ public class SimpleDateFormat extends DateFormat { } /** - * Constructs a SimpleDateFormat using the given pattern in the default + * Constructs a SimpleDateFormat using the given pattern in the default <code>FORMAT</code> * locale. <b>Note:</b> Not all locales support SimpleDateFormat; for full * generality, use the factory methods in the DateFormat class. + * @see Category#FORMAT * @stable ICU 2.0 */ public SimpleDateFormat(String pattern) @@ -432,7 +435,7 @@ public class SimpleDateFormat extends DateFormat { /** * Constructs a SimpleDateFormat using the given pattern and * locale-specific symbol data. - * Warning: uses default locale for digits! + * Warning: uses default <code>FORMAT</code> locale for digits! * @stable ICU 2.0 */ public SimpleDateFormat(String pattern, DateFormatSymbols formatData) @@ -501,7 +504,7 @@ public class SimpleDateFormat extends DateFormat { */ private void initialize() { if (locale == null) { - locale = ULocale.getDefault(); + locale = ULocale.getDefault(Category.FORMAT); } if (formatData == null) { formatData = new DateFormatSymbols(locale); @@ -583,7 +586,7 @@ public class SimpleDateFormat extends DateFormat { * This method is only used by the default SimpleDateFormat constructor. */ private static synchronized String getDefaultPattern() { - ULocale defaultLocale = ULocale.getDefault(); + ULocale defaultLocale = ULocale.getDefault(Category.FORMAT); if (!defaultLocale.equals(cachedDefaultLocale)) { cachedDefaultLocale = defaultLocale; Calendar cal = Calendar.getInstance(cachedDefaultLocale); @@ -2437,7 +2440,7 @@ public class SimpleDateFormat extends DateFormat { // ICU4J 3.6 or older versions did not have UFormat locales // in the serialized data. This is just for preventing the // worst case scenario... - locale = ULocale.getDefault(); + locale = ULocale.getDefault(Category.FORMAT); } initLocalZeroPaddingNumberFormat(); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/TimeUnitFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/TimeUnitFormat.java index d33e062c9e1..c890d7af9cc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/TimeUnitFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/TimeUnitFormat.java @@ -1,6 +1,6 @@ /* ************************************************************************** - * Copyright (C) 2008-2010, Google, International Business Machines + * Copyright (C) 2008-2011, Google, International Business Machines * Corporationand others. All Rights Reserved. ************************************************************************** */ @@ -20,6 +20,7 @@ import com.ibm.icu.util.TimeUnit; import com.ibm.icu.util.TimeUnitAmount; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.ULocale.Category; /** @@ -323,7 +324,7 @@ public class TimeUnitFormat extends MeasureFormat { if (format != null) { locale = format.getLocale(null); } else { - locale = ULocale.getDefault(); + locale = ULocale.getDefault(Category.FORMAT); } } if (format == null) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/CECalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/CECalendar.java index 9e26ac31e73..dd908e536fa 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/CECalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/CECalendar.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2005-2010, International Business Machines Corporation and * + * Copyright (C) 2005-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -9,6 +9,8 @@ package com.ibm.icu.util; import java.util.Date; import java.util.Locale; +import com.ibm.icu.util.ULocale.Category; + /** * Base class for EthiopicCalendar and CopticCalendar. */ @@ -49,20 +51,20 @@ abstract class CECalendar extends Calendar { /** * Constructs a default <code>CECalendar</code> using the current time - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. */ protected CECalendar() { - this(TimeZone.getDefault(), ULocale.getDefault()); + this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); } /** * Constructs a <code>CECalendar</code> based on the current time - * in the given time zone with the default locale. + * in the given time zone with the default <code>FORMAT</code> locale. * * @param zone The time zone for the new calendar. */ protected CECalendar(TimeZone zone) { - this(zone, ULocale.getDefault()); + this(zone, ULocale.getDefault(Category.FORMAT)); } /** @@ -113,7 +115,7 @@ abstract class CECalendar extends Calendar { /** * Constructs a <code>CECalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @@ -123,24 +125,24 @@ abstract class CECalendar extends Calendar { * @param date The value used to set the calendar's {@link #DATE DATE} time field. */ protected CECalendar(int year, int month, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(year, month, date); } /** * Constructs a <code>CECalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. */ protected CECalendar(Date date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); } /** * Constructs a <code>CECalendar</code> with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @param month The value used to set the calendar's {@link #MONTH MONTH} time field. @@ -153,7 +155,7 @@ abstract class CECalendar extends Calendar { protected CECalendar(int year, int month, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(year, month, date, hour, minute, second); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java index 0dc5ff83216..162db725afc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java @@ -25,6 +25,7 @@ import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.DateFormatSymbols; import com.ibm.icu.text.MessageFormat; import com.ibm.icu.text.SimpleDateFormat; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.util.Calendar}.{@icu _usage_} @@ -1484,13 +1485,14 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca /** * Constructs a Calendar with the default time zone - * and locale. + * and the default <code>FORMAT</code> locale. * @see TimeZone#getDefault + * @see Category#FORMAT * @stable ICU 2.0 */ protected Calendar() { - this(TimeZone.getDefault(), ULocale.getDefault()); + this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); } /** @@ -1643,7 +1645,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca */ private static Calendar getInstanceInternal(TimeZone tz, ULocale locale) { if (locale == null) { - locale = ULocale.getDefault(); + locale = ULocale.getDefault(Category.FORMAT); } if (tz == null) { tz = TimeZone.getDefault(); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ChineseCalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ChineseCalendar.java index 3b2661dbc89..f07fc55a546 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/ChineseCalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ChineseCalendar.java @@ -1,5 +1,5 @@ /********************************************************************* - * Copyright (C) 2000-2010, International Business Machines + * Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************* */ @@ -15,6 +15,7 @@ import com.ibm.icu.impl.CalendarAstronomer; import com.ibm.icu.impl.CalendarCache; import com.ibm.icu.text.ChineseDateFormat; import com.ibm.icu.text.DateFormat; +import com.ibm.icu.util.ULocale.Category; /** * <code>ChineseCalendar</code> is a concrete subclass of {@link Calendar} @@ -153,7 +154,7 @@ public class ChineseCalendar extends Calendar { /** * Constructs a <code>ChineseCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @param month The value used to set the calendar's {@link #MONTH MONTH} time field. @@ -161,10 +162,11 @@ public class ChineseCalendar extends Calendar { * @param isLeapMonth The value used to set the Chinese calendar's (@link #IS_LEAP_MONTH) * time field. * @param date The value used to set the calendar's {@link #DATE DATE} time field. + * @see Category#FORMAT * @stable ICU 4.0 */ public ChineseCalendar(int year, int month, int isLeapMonth, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); // We need to set the current time once to initialize the ChineseCalendar's // ERA field to be the current era. @@ -181,7 +183,7 @@ public class ChineseCalendar extends Calendar { /** * Constructs a <code>ChineseCalendar</code> with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * * @param year the value used to set the {@link #YEAR YEAR} time field in the calendar. * @param month the value used to set the {@link #MONTH MONTH} time field in the calendar. @@ -195,12 +197,13 @@ public class ChineseCalendar extends Calendar { * in the calendar. * @param second the value used to set the {@link #SECOND SECOND} time field * in the calendar. + * @see Category#FORMAT * @stable ICU 4.0 */ public ChineseCalendar(int year, int month, int isLeapMonth, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); // We need to set the current time once to initialize the ChineseCalendar's // ERA field to be the current era. @@ -220,7 +223,7 @@ public class ChineseCalendar extends Calendar { /** * Constructs a <code>ChineseCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param era The value used to set the calendar's {@link #ERA ERA} time field. * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. @@ -228,13 +231,14 @@ public class ChineseCalendar extends Calendar { * The value is 0-based. e.g., 0 for January. * @param isLeapMonth The value used to set the Chinese calendar's (@link #IS_LEAP_MONTH) * time field. - * @param date The value used to set the calendar's {@link #DATE DATE} time field. + * @param date The value used to set the calendar's {@link #DATE DATE} time field. + * @see Category#FORMAT * @draft ICU 4.6 * @provisional This API might change or be removed in a future release. */ public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); // We need to set the current time once to initialize the ChineseCalendar's // ERA field to be the current era. @@ -253,7 +257,7 @@ public class ChineseCalendar extends Calendar { /** * Constructs a <code>ChineseCalendar</code> with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * * @param era the value used to set the calendar's {@link #ERA ERA} time field. * @param year the value used to set the {@link #YEAR YEAR} time field in the calendar. @@ -267,14 +271,15 @@ public class ChineseCalendar extends Calendar { * @param minute the value used to set the {@link #MINUTE MINUTE} time field * in the calendar. * @param second the value used to set the {@link #SECOND SECOND} time field - * in the calendar. + * in the calendar. + * @see Category#FORMAT * @draft ICU 4.6 * @provisional This API might change or be removed in a future release. */ public ChineseCalendar(int era, int year, int month, int isLeapMonth, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); // We need to set the current time once to initialize the ChineseCalendar's // ERA field to be the current era. @@ -307,12 +312,13 @@ public class ChineseCalendar extends Calendar { /** * Construct a <code>ChineseCalendar</code> based on the current time - * in the given time zone with the default locale. + * in the given time zone with the default <code>FORMAT</code> locale. * @param zone the given time zone + * @see Category#FORMAT * @stable ICU 4.0 */ public ChineseCalendar(TimeZone zone) { - super(zone, ULocale.getDefault()); + super(zone, ULocale.getDefault(Category.FORMAT)); setTimeInMillis(System.currentTimeMillis()); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java index c612aa1a0df..688c70a6a91 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java @@ -26,6 +26,7 @@ import com.ibm.icu.text.CurrencyDisplayNames; import com.ibm.icu.text.CurrencyMetaInfo; import com.ibm.icu.text.CurrencyMetaInfo.CurrencyDigits; import com.ibm.icu.text.CurrencyMetaInfo.CurrencyFilter; +import com.ibm.icu.util.ULocale.Category; /** * A class encapsulating a currency, as defined by ISO 4217. A @@ -401,12 +402,13 @@ public class Currency extends MeasureUnit implements Serializable { /** * Convenience and compatibility override of getName that - * requests the symbol name. + * requests the symbol name for the default <code>DISPLAY</code> locale. * @see #getName + * @see Category#DISPLAY * @stable ICU 3.4 */ public String getSymbol() { - return getSymbol(ULocale.getDefault()); + return getSymbol(ULocale.getDefault(Category.DISPLAY)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/GregorianCalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/GregorianCalendar.java index aa094865a1a..19994d370a8 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/GregorianCalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/GregorianCalendar.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 1996-2010, International Business Machines + * Copyright (C) 1996-2011, International Business Machines * Corporation and others. All Rights Reserved. */ @@ -8,6 +8,8 @@ package com.ibm.icu.util; import java.util.Date; import java.util.Locale; +import com.ibm.icu.util.ULocale.Category; + /** * {@icuenhanced java.util.GregorianCalendar}.{@icu _usage_} * @@ -327,21 +329,23 @@ public class GregorianCalendar extends Calendar { /** * Constructs a default GregorianCalendar using the current time - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 2.0 */ public GregorianCalendar() { - this(TimeZone.getDefault(), ULocale.getDefault()); + this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); } /** * Constructs a GregorianCalendar based on the current time - * in the given time zone with the default locale. + * in the given time zone with the default <code>FORMAT</code> locale. * @param zone the given time zone. + * @see Category#FORMAT * @stable ICU 2.0 */ public GregorianCalendar(TimeZone zone) { - this(zone, ULocale.getDefault()); + this(zone, ULocale.getDefault(Category.FORMAT)); } /** @@ -390,15 +394,16 @@ public class GregorianCalendar extends Calendar { /** * Constructs a GregorianCalendar with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * @param year the value used to set the YEAR time field in the calendar. * @param month the value used to set the MONTH time field in the calendar. * Month value is 0-based. e.g., 0 for January. * @param date the value used to set the DATE time field in the calendar. + * @see Category#FORMAT * @stable ICU 2.0 */ public GregorianCalendar(int year, int month, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); set(ERA, AD); set(YEAR, year); set(MONTH, month); @@ -407,7 +412,7 @@ public class GregorianCalendar extends Calendar { /** * Constructs a GregorianCalendar with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * @param year the value used to set the YEAR time field in the calendar. * @param month the value used to set the MONTH time field in the calendar. * Month value is 0-based. e.g., 0 for January. @@ -416,11 +421,12 @@ public class GregorianCalendar extends Calendar { * in the calendar. * @param minute the value used to set the MINUTE time field * in the calendar. + * @see Category#FORMAT * @stable ICU 2.0 */ public GregorianCalendar(int year, int month, int date, int hour, int minute) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); set(ERA, AD); set(YEAR, year); set(MONTH, month); @@ -431,7 +437,7 @@ public class GregorianCalendar extends Calendar { /** * Constructs a GregorianCalendar with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * @param year the value used to set the YEAR time field in the calendar. * @param month the value used to set the MONTH time field in the calendar. * Month value is 0-based. e.g., 0 for January. @@ -442,11 +448,12 @@ public class GregorianCalendar extends Calendar { * in the calendar. * @param second the value used to set the SECOND time field * in the calendar. + * @see Category#FORMAT * @stable ICU 2.0 */ public GregorianCalendar(int year, int month, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); set(ERA, AD); set(YEAR, year); set(MONTH, month); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java index e403c590498..864779f0f7c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 1996-2010, International Business Machines Corporation and * + * Copyright (C) 1996-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -9,6 +9,7 @@ import java.util.Date; import java.util.Locale; import com.ibm.icu.impl.CalendarCache; +import com.ibm.icu.util.ULocale.Category; /** * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code> @@ -274,22 +275,24 @@ public class HebrewCalendar extends Calendar { /** * Constructs a default <code>HebrewCalendar</code> using the current time - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar() { - this(TimeZone.getDefault(), ULocale.getDefault()); + this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); } /** * Constructs a <code>HebrewCalendar</code> based on the current time - * in the given time zone with the default locale. + * in the given time zone with the default <code>FORMAT</code> locale. * * @param zone The time zone for the new calendar. + * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar(TimeZone zone) { - this(zone, ULocale.getDefault()); + this(zone, ULocale.getDefault(Category.FORMAT)); } /** @@ -344,7 +347,7 @@ public class HebrewCalendar extends Calendar { /** * Constructs a <code>HebrewCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @@ -352,10 +355,11 @@ public class HebrewCalendar extends Calendar { * The value is 0-based. e.g., 0 for Tishri. * * @param date The value used to set the calendar's {@link #DATE DATE} time field. + * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar(int year, int month, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(YEAR, year); this.set(MONTH, month); this.set(DATE, date); @@ -363,19 +367,20 @@ public class HebrewCalendar extends Calendar { /** * Constructs a <code>HebrewCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. + * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar(Date date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); } /** * Constructs a <code>HebrewCalendar</code> with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @@ -389,12 +394,13 @@ public class HebrewCalendar extends Calendar { * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field. * * @param second The value used to set the calendar's {@link #SECOND SECOND} time field. + * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar(int year, int month, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(YEAR, year); this.set(MONTH, month); this.set(DATE, date); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Holiday.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Holiday.java index d80a1492a40..fa2525065a6 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Holiday.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Holiday.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 1996-2010, International Business Machines Corporation and * + * Copyright (C) 1996-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -12,6 +12,8 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import com.ibm.icu.util.ULocale.Category; + /** * <b>Note:</b> The Holiday framework is a technology preview. * Despite its age, is still draft API, and clients should treat it as such. @@ -28,7 +30,7 @@ public abstract class Holiday implements DateRule */ public static Holiday[] getHolidays() { - return getHolidays(ULocale.getDefault()); + return getHolidays(ULocale.getDefault(Category.FORMAT)); } /** @@ -138,12 +140,13 @@ public abstract class Holiday implements DateRule } /** - * Return the name of this holiday in the language of the default locale. + * Return the name of this holiday in the language of the default <code>DISPLAY</code> locale. + * @see Category#DISPLAY * @draft ICU 2.8 * @provisional This API might change or be removed in a future release. */ public String getDisplayName() { - return getDisplayName(ULocale.getDefault()); + return getDisplayName(ULocale.getDefault(Category.DISPLAY)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/IndianCalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/IndianCalendar.java index 015a6895066..eef93776e75 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/IndianCalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/IndianCalendar.java @@ -10,6 +10,8 @@ package com.ibm.icu.util; import java.util.Date; import java.util.Locale; +import com.ibm.icu.util.ULocale.Category; + /** * <code>IndianCalendar</code> is a subclass of <code>GregorianCalendar</code> * that numbers years since the birth of the Buddha. This is the civil calendar @@ -153,22 +155,24 @@ public class IndianCalendar extends Calendar { /** * Constructs a <code>IndianCalendar</code> using the current time - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar() { - this(TimeZone.getDefault(), ULocale.getDefault()); + this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); } /** * Constructs a <code>IndianCalendar</code> based on the current time - * in the given time zone with the default locale. + * in the given time zone with the default <code>FORMAT</code> locale. * * @param zone the given time zone. + * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar(TimeZone zone) { - this(zone, ULocale.getDefault()); + this(zone, ULocale.getDefault(Category.FORMAT)); } /** @@ -223,19 +227,20 @@ public class IndianCalendar extends Calendar { /** * Constructs a <code>IndianCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. + * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar(Date date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); } /** * Constructs a <code>IndianCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @@ -243,10 +248,11 @@ public class IndianCalendar extends Calendar { * The value is 0-based. e.g., 0 for January. * * @param date The value used to set the calendar's {@link #DATE DATE} time field. + * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar(int year, int month, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(Calendar.YEAR, year); this.set(Calendar.MONTH, month); this.set(Calendar.DATE, date); @@ -255,7 +261,7 @@ public class IndianCalendar extends Calendar { /** * Constructs a IndianCalendar with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. * @@ -269,12 +275,13 @@ public class IndianCalendar extends Calendar { * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field. * * @param second The value used to set the calendar's {@link #SECOND SECOND} time field. + * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar(int year, int month, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(Calendar.YEAR, year); this.set(Calendar.MONTH, month); this.set(Calendar.DATE, date); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/IslamicCalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/IslamicCalendar.java index 4f67db0a628..bd3f3457901 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/IslamicCalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/IslamicCalendar.java @@ -10,6 +10,7 @@ import java.util.Locale; import com.ibm.icu.impl.CalendarAstronomer; import com.ibm.icu.impl.CalendarCache; +import com.ibm.icu.util.ULocale.Category; /** * <code>IslamicCalendar</code> is a subclass of <code>Calendar</code> @@ -163,23 +164,25 @@ public class IslamicCalendar extends Calendar { /** * Constructs a default <code>IslamicCalendar</code> using the current time - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. + * @see Category#FORMAT * @stable ICU 2.8 */ public IslamicCalendar() { - this(TimeZone.getDefault(), ULocale.getDefault()); + this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); } /** * Constructs an <code>IslamicCalendar</code> based on the current time - * in the given time zone with the default locale. + * in the given time zone with the default <code>FORMAT</code> locale. * @param zone the given time zone. + * @see Category#FORMAT * @stable ICU 2.8 */ public IslamicCalendar(TimeZone zone) { - this(zone, ULocale.getDefault()); + this(zone, ULocale.getDefault(Category.FORMAT)); } /** @@ -236,29 +239,31 @@ public class IslamicCalendar extends Calendar { /** * Constructs an <code>IslamicCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. + * @see Category#FORMAT * @stable ICU 2.8 */ public IslamicCalendar(Date date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); } /** * Constructs an <code>IslamicCalendar</code> with the given date set - * in the default time zone with the default locale. + * in the default time zone with the default <code>FORMAT</code> locale. * * @param year the value used to set the {@link #YEAR YEAR} time field in the calendar. * @param month the value used to set the {@link #MONTH MONTH} time field in the calendar. * Note that the month value is 0-based. e.g., 0 for Muharram. * @param date the value used to set the {@link #DATE DATE} time field in the calendar. + * @see Category#FORMAT * @stable ICU 2.8 */ public IslamicCalendar(int year, int month, int date) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(Calendar.YEAR, year); this.set(Calendar.MONTH, month); this.set(Calendar.DATE, date); @@ -266,7 +271,7 @@ public class IslamicCalendar extends Calendar { /** * Constructs an <code>IslamicCalendar</code> with the given date - * and time set for the default time zone with the default locale. + * and time set for the default time zone with the default <code>FORMAT</code> locale. * * @param year the value used to set the {@link #YEAR YEAR} time field in the calendar. * @param month the value used to set the {@link #MONTH MONTH} time field in the calendar. @@ -278,12 +283,13 @@ public class IslamicCalendar extends Calendar { * in the calendar. * @param second the value used to set the {@link #SECOND SECOND} time field * in the calendar. + * @see Category#FORMAT * @stable ICU 2.8 */ public IslamicCalendar(int year, int month, int date, int hour, int minute, int second) { - super(TimeZone.getDefault(), ULocale.getDefault()); + super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.set(Calendar.YEAR, year); this.set(Calendar.MONTH, month); this.set(Calendar.DATE, date); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java index 59157af5983..ebbdb8b02e7 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java @@ -1,6 +1,6 @@ /* ************************************************************************************** - * Copyright (C) 2009-2010, Google, Inc.; International Business Machines Corporation * + * Copyright (C) 2009-2011, Google, Inc.; International Business Machines Corporation * * and others. All Rights Reserved. * ************************************************************************************** */ @@ -10,6 +10,7 @@ import java.util.MissingResourceException; import com.ibm.icu.impl.ICUResourceBundle; import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.ULocale.Category; /** * A class for accessing miscelleneous data in the locale bundles @@ -189,13 +190,14 @@ public final class LocaleData { } /** - * Gets the LocaleData object associated with the default locale + * Gets the LocaleData object associated with the default <code>FORMAT</code> locale * * @return A locale data object. + * @see Category#FORMAT * @stable ICU 3.4 */ public static final LocaleData getInstance() { - return LocaleData.getInstance(ULocale.getDefault()); + return LocaleData.getInstance(ULocale.getDefault(Category.FORMAT)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java index c9d3b70790e..604f80b3539 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java @@ -24,6 +24,7 @@ import com.ibm.icu.text.TimeZoneFormat.Style; import com.ibm.icu.text.TimeZoneFormat.TimeType; import com.ibm.icu.text.TimeZoneNames; import com.ibm.icu.text.TimeZoneNames.NameType; +import com.ibm.icu.util.ULocale.Category; /** * {@icuenhanced java.util.TimeZone}.{@icu _usage_} @@ -373,15 +374,16 @@ abstract public class TimeZone implements Serializable, Cloneable { /** * Returns a name of this time zone suitable for presentation to the user - * in the default locale. + * in the default <code>DISPLAY</code> locale. * This method returns the long generic name. * If the display name is not available for the locale, * a fallback based on the country, city, or time zone id will be used. * @return the human-readable name of this time zone in the default locale. + * @see Category#DISPLAY * @stable ICU 2.0 */ public final String getDisplayName() { - return _getDisplayName(LONG_GENERIC, false, ULocale.getDefault()); + return _getDisplayName(LONG_GENERIC, false, ULocale.getDefault(Category.DISPLAY)); } /** @@ -416,7 +418,7 @@ abstract public class TimeZone implements Serializable, Cloneable { /** * Returns a name of this time zone suitable for presentation to the user - * in the default locale. + * in the default <code>DISPLAY</code> locale. * If the display name is not available for the locale, * then this method returns a string in the localized GMT offset format * such as <code>GMT[+-]HH:mm</code>. @@ -426,10 +428,11 @@ abstract public class TimeZone implements Serializable, Cloneable { * <code>LONG_GENERIC</code>, <code>SHORT_GMT</code>, <code>LONG_GMT</code>, * <code>SHORT_COMMONLY_USED</code> or <code>GENERIC_LOCATION</code>. * @return the human-readable name of this time zone in the default locale. + * @see Category#DISPLAY * @stable ICU 2.0 */ public final String getDisplayName(boolean daylight, int style) { - return getDisplayName(daylight, style, ULocale.getDefault()); + return getDisplayName(daylight, style, ULocale.getDefault(Category.DISPLAY)); } /** diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java index a70c980ec63..b40d2d7f605 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java @@ -254,6 +254,24 @@ public final class ULocale implements Serializable { */ public static final ULocale ROOT = new ULocale("", EMPTY_LOCALE); + /** + * Enum for locale categories. These locale categories are used to get/set the default locale for + * the specific functionality represented by the category. + * @stable ICU 49 + */ + public enum Category { + /** + * Category used to represent the default locale for displaying user interfaces. + * @stable ICU 49 + */ + DISPLAY, + /** + * Category used to represent the default locale for formatting date, number and/or currency. + * @stable ICU 49 + */ + FORMAT + } + private static final SimpleCache<Locale, ULocale> CACHE = new SimpleCache<Locale, ULocale>(); /** @@ -393,11 +411,7 @@ public final class ULocale implements Serializable { } ULocale result = CACHE.get(loc); if (result == null) { - if (defaultULocale != null && loc == defaultULocale.locale) { - result = defaultULocale; - } else { - result = JDKLocaleMapper.INSTANCE.toULocale(loc); - } + result = JDKLocaleHelper.toULocale(loc); CACHE.put(loc, result); } return result; @@ -503,29 +517,37 @@ public final class ULocale implements Serializable { */ public Locale toLocale() { if (locale == null) { - locale = JDKLocaleMapper.INSTANCE.toLocale(this); + locale = JDKLocaleHelper.toLocale(this); } return locale; } private static ICUCache<String, String> nameCache = new SimpleCache<String, String>(); + /** * Keep our own default ULocale. */ private static Locale defaultLocale = Locale.getDefault(); - private static ULocale defaultULocale = new ULocale(defaultLocale); + private static ULocale defaultULocale = forLocale(defaultLocale); + + private static Locale[] defaultCategoryLocales = new Locale[Category.values().length]; + private static ULocale[] defaultCategoryULocales = new ULocale[Category.values().length]; + + static { + for (Category cat: Category.values()) { + int idx = cat.ordinal(); + defaultCategoryLocales[idx] = JDKLocaleHelper.getDefault(cat); + defaultCategoryULocales[idx] = forLocale(defaultCategoryLocales[idx]); + } + } /** * Returns the current default ULocale. + * @return the default ULocale. * @stable ICU 2.8 */ public static ULocale getDefault() { synchronized (ULocale.class) { - Locale currentDefault = Locale.getDefault(); - if (!defaultLocale.equals(currentDefault)) { - defaultLocale = currentDefault; - defaultULocale = new ULocale(defaultLocale); - } if (defaultULocale == null) { // When Java's default locale has extensions (such as ja-JP-u-ca-japanese), // Locale -> ULocale mapping requires BCP47 keyword mapping data that is currently @@ -537,6 +559,22 @@ public final class ULocale implements Serializable { return ULocale.ROOT; } + Locale currentDefault = Locale.getDefault(); + if (!defaultLocale.equals(currentDefault)) { + defaultLocale = currentDefault; + defaultULocale = forLocale(currentDefault); + + if (!JDKLocaleHelper.isJava7orNewer()) { + // Detected Java default Locale change. + // We need to update category defaults to match the + // Java 7's behavior on Java 6 or older environment. + for (Category cat : Category.values()) { + int idx = cat.ordinal(); + defaultCategoryLocales[idx] = currentDefault; + defaultCategoryULocales[idx] = forLocale(currentDefault); + } + } + } return defaultULocale; } } @@ -546,17 +584,100 @@ public final class ULocale implements Serializable { * If the caller does not have write permission to the * user.language property, a security exception will be thrown, * and the default ULocale will remain unchanged. + * <p> + * By setting the default ULocale with this method, all of the default categoy locales + * are also set to the specified default ULocale. * @param newLocale the new default locale * @throws SecurityException if a security manager exists and its * <code>checkPermission</code> method doesn't allow the operation. * @throws NullPointerException if <code>newLocale</code> is null * @see SecurityManager#checkPermission(java.security.Permission) * @see java.util.PropertyPermission + * @see ULocale#setDefault(Category, ULocale) * @stable ICU 3.0 */ public static synchronized void setDefault(ULocale newLocale){ Locale.setDefault(newLocale.toLocale()); defaultULocale = newLocale; + // This method also updates all category default locales + for (Category cat : Category.values()) { + setDefault(cat, newLocale); + } + } + + /** + * Returns the current default ULocale for the specified category. + * + * @param category the category + * @return the default ULocale for the specified category. + * @stable ICU 49 + */ + public static ULocale getDefault(Category category) { + synchronized (ULocale.class) { + int idx = category.ordinal(); + if (defaultCategoryULocales[idx] == null) { + // Just in case this method is called during ULocale class + // initialization. Unlike getDefault(), we do not have + // cyclic dependency for category default. + return ULocale.ROOT; + } + if (JDKLocaleHelper.isJava7orNewer()) { + Locale currentCategoryDefault = JDKLocaleHelper.getDefault(category); + if (!defaultCategoryLocales[idx].equals(currentCategoryDefault)) { + defaultCategoryLocales[idx] = currentCategoryDefault; + defaultCategoryULocales[idx] = forLocale(currentCategoryDefault); + } + } else { + // java.util.Locale.setDefault(Locale) in Java 7 updates + // category locale defaults. On Java 6 or older environment, + // ICU4J checks if the default locale has changed and update + // category ULocales here if necessary. + + // Note: When java.util.Locale.setDefault(Locale) is called + // with a Locale same with the previous one, Java 7 still + // updates category locale defaults. On Java 6 or older env, + // there is no good way to detect the event, ICU4J simply + // check if the default Java Locale has changed since last + // time. + + Locale currentDefault = Locale.getDefault(); + if (!defaultLocale.equals(currentDefault)) { + defaultLocale = currentDefault; + defaultULocale = forLocale(currentDefault); + + for (Category cat : Category.values()) { + int tmpIdx = cat.ordinal(); + defaultCategoryLocales[tmpIdx] = currentDefault; + defaultCategoryULocales[tmpIdx] = forLocale(currentDefault); + } + } + + // No synchronization with JDK Locale, because category default + // is not supported in Java 6 or older versions + } + return defaultCategoryULocales[idx]; + } + } + + /** + * Sets the default <code>ULocale</code> for the specified <code>Category</code>. + * This also sets the default <code>Locale</code> for the specified <code>Category</code> + * of the JVM. If the caller does not have write permission to the + * user.language property, a security exception will be thrown, + * and the default ULocale for the specified Category will remain unchanged. + * + * @param category the specified category to set the default locale + * @param newLocale the new default locale + * @see SecurityManager#checkPermission(java.security.Permission) + * @see java.util.PropertyPermission + * @stable ICU 49 + */ + public static synchronized void setDefault(Category category, ULocale newLocale) { + Locale newJavaDefault = newLocale.toLocale(); + int idx = category.ordinal(); + defaultCategoryULocales[idx] = newLocale; + defaultCategoryLocales[idx] = newJavaDefault; + JDKLocaleHelper.setDefault(category, newJavaDefault); } /** @@ -1067,12 +1188,13 @@ public final class ULocale implements Serializable { // display names /** - * Returns this locale's language localized for display in the default locale. + * Returns this locale's language localized for display in the default <code>DISPLAY</code> locale. * @return the localized language name. + * @see Category#DISPLAY * @stable ICU 3.0 */ public String getDisplayLanguage() { - return getDisplayLanguageInternal(this, getDefault(), false); + return getDisplayLanguageInternal(this, getDefault(Category.DISPLAY), false); } /** @@ -1110,13 +1232,14 @@ public final class ULocale implements Serializable { return getDisplayLanguageInternal(new ULocale(localeID), displayLocale, false); } /** - * {@icu} Returns this locale's language localized for display in the default locale. + * {@icu} Returns this locale's language localized for display in the default <code>DISPLAY</code> locale. * If a dialect name is present in the data, then it is returned. * @return the localized language name. + * @see Category#DISPLAY * @stable ICU 4.4 */ public String getDisplayLanguageWithDialect() { - return getDisplayLanguageInternal(this, getDefault(), true); + return getDisplayLanguageInternal(this, getDefault(Category.DISPLAY), true); } /** @@ -1164,12 +1287,13 @@ public final class ULocale implements Serializable { } /** - * {@icu} Returns this locale's script localized for display in the default locale. + * {@icu} Returns this locale's script localized for display in the default <code>DISPLAY</code> locale. * @return the localized script name. + * @see Category#DISPLAY * @stable ICU 3.0 */ public String getDisplayScript() { - return getDisplayScriptInternal(this, getDefault()); + return getDisplayScriptInternal(this, getDefault(Category.DISPLAY)); } /** @@ -1212,12 +1336,13 @@ public final class ULocale implements Serializable { } /** - * Returns this locale's country localized for display in the default locale. + * Returns this locale's country localized for display in the default <code>DISPLAY</code> locale. * @return the localized country name. + * @see Category#DISPLAY * @stable ICU 3.0 */ public String getDisplayCountry() { - return getDisplayCountryInternal(this, getDefault()); + return getDisplayCountryInternal(this, getDefault(Category.DISPLAY)); } /** @@ -1261,12 +1386,13 @@ public final class ULocale implements Serializable { } /** - * Returns this locale's variant localized for display in the default locale. + * Returns this locale's variant localized for display in the default <code>DISPLAY</code> locale. * @return the localized variant name. + * @see Category#DISPLAY * @stable ICU 3.0 */ public String getDisplayVariant() { - return getDisplayVariantInternal(this, getDefault()); + return getDisplayVariantInternal(this, getDefault(Category.DISPLAY)); } /** @@ -1309,14 +1435,15 @@ public final class ULocale implements Serializable { } /** - * {@icu} Returns a keyword localized for display in the default locale. + * {@icu} Returns a keyword localized for display in the default <code>DISPLAY</code> locale. * @param keyword the keyword to be displayed. * @return the localized keyword name. * @see #getKeywords() + * @see Category#DISPLAY * @stable ICU 3.0 */ public static String getDisplayKeyword(String keyword) { - return getDisplayKeywordInternal(keyword, getDefault()); + return getDisplayKeywordInternal(keyword, getDefault(Category.DISPLAY)); } /** @@ -1348,13 +1475,14 @@ public final class ULocale implements Serializable { } /** - * {@icu} Returns a keyword value localized for display in the default locale. + * {@icu} Returns a keyword value localized for display in the default <code>DISPLAY</code> locale. * @param keyword the keyword whose value is to be displayed. * @return the localized value name. + * @see Category#DISPLAY * @stable ICU 3.0 */ public String getDisplayKeywordValue(String keyword) { - return getDisplayKeywordValueInternal(this, keyword, getDefault()); + return getDisplayKeywordValueInternal(this, keyword, getDefault(Category.DISPLAY)); } /** @@ -1406,12 +1534,13 @@ public final class ULocale implements Serializable { } /** - * Returns this locale name localized for display in the default locale. + * Returns this locale name localized for display in the default <code>DISPLAY</code> locale. * @return the localized locale name. + * @see Category#DISPLAY * @stable ICU 3.0 */ public String getDisplayName() { - return getDisplayNameInternal(this, getDefault()); + return getDisplayNameInternal(this, getDefault(Category.DISPLAY)); } /** @@ -1453,13 +1582,14 @@ public final class ULocale implements Serializable { } /** - * {@icu} Returns this locale name localized for display in the default locale. + * {@icu} Returns this locale name localized for display in the default <code>DISPLAY</code> locale. * If a dialect name is present in the locale data, then it is returned. * @return the localized locale name. + * @see Category#DISPLAY * @stable ICU 4.4 */ public String getDisplayNameWithDialect() { - return getDisplayNameWithDialectInternal(this, getDefault()); + return getDisplayNameWithDialectInternal(this, getDefault(Category.DISPLAY)); } /** @@ -3522,11 +3652,9 @@ public final class ULocale implements Serializable { } /* - * JDK Locale Mapper + * JDK Locale Helper */ - private static final class JDKLocaleMapper { - public static final JDKLocaleMapper INSTANCE = new JDKLocaleMapper(); - + private static final class JDKLocaleHelper { private static boolean isJava7orNewer = false; /* @@ -3540,6 +3668,11 @@ public final class ULocale implements Serializable { private static Method mGetUnicodeLocaleType; private static Method mForLanguageTag; + private static Method mGetDefault; + private static Method mSetDefault; + private static Object eDISPLAY; + private static Object eFORMAT; + /* * This table is used for mapping between ICU and special Java * 6 locales. When an ICU locale matches <minumum base> with @@ -3556,32 +3689,70 @@ public final class ULocale implements Serializable { }; static { - try { - mGetScript = Locale.class.getMethod("getScript", (Class[]) null); - mGetExtensionKeys = Locale.class.getMethod("getExtensionKeys", (Class[]) null); - mGetExtension = Locale.class.getMethod("getExtension", char.class); - mGetUnicodeLocaleKeys = Locale.class.getMethod("getUnicodeLocaleKeys", (Class[]) null); - mGetUnicodeLocaleAttributes = Locale.class.getMethod("getUnicodeLocaleAttributes", (Class[]) null); - mGetUnicodeLocaleType = Locale.class.getMethod("getUnicodeLocaleType", String.class); - mForLanguageTag = Locale.class.getMethod("forLanguageTag", String.class); - isJava7orNewer = true; - } catch (NoSuchMethodException e) { - // Java 6 or older - } + do { + try { + mGetScript = Locale.class.getMethod("getScript", (Class[]) null); + mGetExtensionKeys = Locale.class.getMethod("getExtensionKeys", (Class[]) null); + mGetExtension = Locale.class.getMethod("getExtension", char.class); + mGetUnicodeLocaleKeys = Locale.class.getMethod("getUnicodeLocaleKeys", (Class[]) null); + mGetUnicodeLocaleAttributes = Locale.class.getMethod("getUnicodeLocaleAttributes", (Class[]) null); + mGetUnicodeLocaleType = Locale.class.getMethod("getUnicodeLocaleType", String.class); + mForLanguageTag = Locale.class.getMethod("forLanguageTag", String.class); + + Class<?> cCategory = null; + Class<?>[] classes = Locale.class.getDeclaredClasses(); + for (Class<?> c : classes) { + if (c.getName().equals("java.util.Locale$Category")) { + cCategory = c; + break; + } + } + if (cCategory == null) { + break; + } + mGetDefault = Locale.class.getDeclaredMethod("getDefault", cCategory); + mSetDefault = Locale.class.getDeclaredMethod("setDefault", cCategory, Locale.class); + + Method mName = cCategory.getMethod("name", (Class[]) null); + Object[] enumConstants = cCategory.getEnumConstants(); + for (Object e : enumConstants) { + String catVal = (String)mName.invoke(e, (Object[])null); + if (catVal.equals("DISPLAY")) { + eDISPLAY = e; + } else if (catVal.equals("FORMAT")) { + eFORMAT = e; + } + } + if (eDISPLAY == null || eFORMAT == null) { + break; + } + isJava7orNewer = true; + } catch (NoSuchMethodException e) { + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } catch (SecurityException e) { + // TODO : report? + } + } while (false); + } + + private JDKLocaleHelper() { } - private JDKLocaleMapper() { + public static boolean isJava7orNewer() { + return isJava7orNewer; } - public ULocale toULocale(Locale loc) { + public static ULocale toULocale(Locale loc) { return isJava7orNewer ? toULocale7(loc) : toULocale6(loc); } - public Locale toLocale(ULocale uloc) { + public static Locale toLocale(ULocale uloc) { return isJava7orNewer ? toLocale7(uloc) : toLocale6(uloc); } - private ULocale toULocale7(Locale loc) { + private static ULocale toULocale7(Locale loc) { String language = loc.getLanguage(); String script = ""; String country = loc.getCountry(); @@ -3718,7 +3889,7 @@ public final class ULocale implements Serializable { return new ULocale(getName(buf.toString()), loc); } - private ULocale toULocale6(Locale loc) { + private static ULocale toULocale6(Locale loc) { ULocale uloc = null; String locStr = loc.toString(); if (locStr.length() == 0) { @@ -3737,7 +3908,7 @@ public final class ULocale implements Serializable { return uloc; } - private Locale toLocale7(ULocale uloc) { + private static Locale toLocale7(ULocale uloc) { Locale loc = null; String ulocStr = uloc.getName(); if (uloc.getScript().length() > 0 || ulocStr.contains("@")) { @@ -3778,7 +3949,7 @@ public final class ULocale implements Serializable { return loc; } - private Locale toLocale6(ULocale uloc) { + private static Locale toLocale6(ULocale uloc) { String locstr = uloc.getBaseName(); for (int i = 0; i < JAVA6_MAPDATA.length; i++) { if (locstr.equals(JAVA6_MAPDATA[i][1]) || locstr.equals(JAVA6_MAPDATA[i][4])) { @@ -3798,5 +3969,57 @@ public final class ULocale implements Serializable { String[] names = p.getLanguageScriptCountryVariant(); return new Locale(names[0], names[2], names[3]); } + + public static Locale getDefault(Category category) { + Locale loc = Locale.getDefault(); + if (isJava7orNewer) { + Object cat = null; + switch (category) { + case DISPLAY: + cat = eDISPLAY; + break; + case FORMAT: + cat = eFORMAT; + break; + } + if (cat != null) { + try { + loc = (Locale)mGetDefault.invoke(null, cat); + } catch (InvocationTargetException e) { + // fall through - use the base default + } catch (IllegalArgumentException e) { + // fall through - use the base default + } catch (IllegalAccessException e) { + // fall through - use the base default + } + } + } + return loc; + } + + public static void setDefault(Category category, Locale newLocale) { + if (isJava7orNewer) { + Object cat = null; + switch (category) { + case DISPLAY: + cat = eDISPLAY; + break; + case FORMAT: + cat = eFORMAT; + break; + } + if (cat != null) { + try { + mSetDefault.invoke(null, cat, newLocale); + } catch (InvocationTargetException e) { + // fall through - no effects + } catch (IllegalArgumentException e) { + // fall through - no effects + } catch (IllegalAccessException e) { + // fall through - no effects + } + } + } + } } } diff --git a/icu4j/main/classes/translit/src/com/ibm/icu/text/Transliterator.java b/icu4j/main/classes/translit/src/com/ibm/icu/text/Transliterator.java index 729f1b2778f..76e7dcd3aee 100644 --- a/icu4j/main/classes/translit/src/com/ibm/icu/text/Transliterator.java +++ b/icu4j/main/classes/translit/src/com/ibm/icu/text/Transliterator.java @@ -24,6 +24,7 @@ import com.ibm.icu.text.TransliteratorIDParser.SingleID; import com.ibm.icu.util.CaseInsensitiveString; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.ULocale.Category; /** * <code>Transliterator</code> is an abstract class that transliterates text from one format to another. The most common @@ -1153,12 +1154,13 @@ public abstract class Transliterator implements StringTransform { /** * Returns a name for this transliterator that is appropriate for - * display to the user in the default locale. See {@link + * display to the user in the default <code>DISPLAY</code> locale. See {@link * #getDisplayName(String,Locale)} for details. + * @see com.ibm.icu.util.ULocale.Category#DISPLAY * @stable ICU 2.0 */ public final static String getDisplayName(String ID) { - return getDisplayName(ID, ULocale.getDefault()); + return getDisplayName(ID, ULocale.getDefault(Category.DISPLAY)); } /** diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index 28acd2dbfb4..e43db659725 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -33,6 +33,7 @@ import com.ibm.icu.util.IllformedLocaleException; import com.ibm.icu.util.LocaleData; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Builder; +import com.ibm.icu.util.ULocale.Category; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.VersionInfo; @@ -4154,4 +4155,63 @@ public class ULocaleTest extends TestFmwk { } } } + + public void TestCategoryDefault() { + Locale backupDefault = Locale.getDefault(); + + ULocale orgDefault = ULocale.getDefault(); + + // Setting a category default won't change default ULocale + ULocale uJaJp = new ULocale("ja_JP"); + ULocale uDeDePhonebook = new ULocale("de_DE@collation=phonebook"); + + ULocale.setDefault(Category.DISPLAY, uJaJp); + ULocale.setDefault(Category.FORMAT, uDeDePhonebook); + + if (!ULocale.getDefault().equals(orgDefault)) { + errln("FAIL: Default ULocale is " + ULocale.getDefault() + ", expected: " + orgDefault); + } + + if (!ULocale.getDefault(Category.DISPLAY).equals(uJaJp)) { + errln("FAIL: DISPLAY ULocale is " + ULocale.getDefault(Category.DISPLAY) + ", expected: " + uJaJp); + } + + if (!ULocale.getDefault(Category.FORMAT).equals(uDeDePhonebook)) { + errln("FAIL: FORMAT ULocale is " + ULocale.getDefault(Category.FORMAT) + ", expected: " + uDeDePhonebook); + } + + // Setting ULocale default will overrides category defaults + ULocale uFrFr = new ULocale("fr_FR"); + + ULocale.setDefault(uFrFr); + + if (!ULocale.getDefault(Category.DISPLAY).equals(uFrFr)) { + errln("FAIL: DISPLAY ULocale is " + ULocale.getDefault(Category.DISPLAY) + ", expected: " + uFrFr); + } + + if (!ULocale.getDefault(Category.FORMAT).equals(uFrFr)) { + errln("FAIL: FORMAT ULocale is " + ULocale.getDefault(Category.FORMAT) + ", expected: " + uFrFr); + } + + // Setting Locale default will updates ULocale default and category defaults + Locale arEg = new Locale("ar", "EG"); + ULocale uArEg = ULocale.forLocale(arEg); + + Locale.setDefault(arEg); + + if (!ULocale.getDefault().equals(uArEg)) { + errln("FAIL: Default ULocale is " + ULocale.getDefault() + ", expected: " + uArEg); + } + + if (!ULocale.getDefault(Category.DISPLAY).equals(uArEg)) { + errln("FAIL: DISPLAY ULocale is " + ULocale.getDefault(Category.DISPLAY) + ", expected: " + uArEg); + } + + if (!ULocale.getDefault(Category.FORMAT).equals(uArEg)) { + errln("FAIL: FORMAT ULocale is " + ULocale.getDefault(Category.FORMAT) + ", expected: " + uArEg); + } + + // Restore back up + Locale.setDefault(backupDefault); + } } -- 2.40.0