com.ibm.icu.util

Class GlobalizationPreferences

public class GlobalizationPreferences extends Object implements Freezable

Deprecated: This API is ICU internal only.

This convenience class provides a mechanism for bundling together different globalization preferences. It includes: The class will heuristically compute implicit, heuristic values for the above based on available data if explicit values are not supplied. These implicit values can be presented to users for confirmation, or replacement if the values are incorrect.

To reset any explicit field so that it will get heuristic values, pass in null. For example, myPreferences.setLocale(null);

All of the heuristics can be customized by subclasses, by overriding getTerritory(), guessCollator(), etc.

The class also supplies display names for languages, scripts, territories, currencies, timezones, etc. These are computed according to the locale/language preference list. Thus, if the preference is Breton; French; English, then the display name for a language will be returned in Breton if available, otherwise in French if available, otherwise in English.

The codes used to reference territory, currency, etc. are as defined elsewhere in ICU, and are taken from CLDR (which reflects RFC 3066bis usage, ISO 4217, and the TZ Timezone database identifiers).

This is at a prototype stage, and has not incorporated all the design changes that we would like yet; further feedback is welcome.

TODO:

Note:

UNKNOWN:

Field Summary
static intCURRENCY
Number Format types
static intCURRENCYID
For selecting a choice of display names
static intCURRENCY_SYMBOLID
For selecting a choice of display names
static intDISPLAYID_LIMIT
For selecting a choice of display names
static intINTEGER
Number Format types
static intKEYWORDID
For selecting a choice of display names
static intKEYWORD_VALUEID
For selecting a choice of display names
static intLANGUAGEID
For selecting a choice of display names
static intLOCALEID
For selecting a choice of display names
static intNONE
Supplement to DateFormat.FULL, LONG, MEDIUM, SHORT.
static intNUMBER
Number Format types
static intNUMBER_LIMIT
Number Format types
static intPERCENT
Number Format types
static intSCIENTIFIC
Number Format types
static intSCRIPTID
For selecting a choice of display names
static intTERRITORYID
For selecting a choice of display names
static intTIMEZONEID
For selecting a choice of display names
static intVARIANTID
For selecting a choice of display names
Method Summary
ObjectcloneAsThawed()
Objectfreeze()
CalendargetCalendar()
Get a copy of the calendar according to the settings.
CollatorgetCollator()
Get a copy of the collator according to the settings.
CurrencygetCurrency()
Get a copy of the currency computed according to the settings.
DateFormatgetDateFormat(int dateStyle, int timeStyle)
Gets a date format according to the current settings.
ULocalegetDateLocale()
Gets the date locale, to be used in computing date formats.
StringgetDisplayName(String id, int type)
Get the display name for an ID: language, script, territory, currency, timezone...
ULocalegetLocale(int index)
Convenience function for getting the locales in priority order
ListgetLocales()
Get a copy of the language/locale priority list
NumberFormatgetNumberFormat(int style)
Gets a number format according to the current settings.
ULocalegetNumberLocale()
Get the current number locale setting used for getNumberFormat.
StringgetTerritory()
Gets the territory setting.
TimeZonegetTimeZone()
Get the timezone.
protected CalendarguessCalendar()
This function can be overridden by subclasses to use different heuristics.
protected CollatorguessCollator()
This function can be overridden by subclasses to use different heuristics.
protected CurrencyguessCurrency()
This function can be overridden by subclasses to use different heuristics
protected ListguessLocales()
This function can be overridden by subclasses to use different heuristics It MUST return a 'safe' value, one whose modification will not affect this object.
protected StringguessTerritory()
This function can be overridden by subclasses to use different heuristics.
protected TimeZoneguessTimeZone()
This function can be overridden by subclasses to use different heuristics.
booleanisFrozen()
GlobalizationPreferencesreset()
Restore the object to the initial state.
GlobalizationPreferencessetCalendar(Calendar calendar)
Sets the calendar.
GlobalizationPreferencessetCollator(Collator collator)
Explicitly set the collator for this object.
GlobalizationPreferencessetCurrency(Currency currency)
Sets the currency code.
GlobalizationPreferencessetDateFormat(int dateStyle, int timeStyle, DateFormat format)
Set an explicit date format.
GlobalizationPreferencessetDateFormat(int dateStyle, int timeStyle, String formatPattern)
Set an explicit date format.
GlobalizationPreferencessetDateLocale(ULocale dateLocale)
Set the date locale.
GlobalizationPreferencessetLocale(ULocale uLocale)
Convenience routine for setting the language/locale priority list from a single locale/language.
GlobalizationPreferencessetLocales(List locales)
Sets the language/locale priority list.
GlobalizationPreferencessetLocales(ULocale[] uLocales)
Convenience routine for setting the language/locale priority list from an array.
GlobalizationPreferencessetLocales(String acceptLanguageString)
Convenience routine for setting the locale priority list from an Accept-Language string.
GlobalizationPreferencessetNumberFormat(int style, DateFormat format)
Sets a number format explicitly.
GlobalizationPreferencessetNumberFormat(int style, String formatPattern)
Sets a number format explicitly.
GlobalizationPreferencessetNumberLocale(ULocale numberLocale)
Set the number locale.
GlobalizationPreferencessetTerritory(String territory)
Sets the territory, which is a valid territory according to for RFC 3066 (or successor).
GlobalizationPreferencessetTimeZone(TimeZone timezone)
Sets the timezone ID.

Field Detail

CURRENCY

public static final int CURRENCY

Deprecated: This API is ICU internal only.

Number Format types

UNKNOWN:

CURRENCYID

public static final int CURRENCYID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

CURRENCY_SYMBOLID

public static final int CURRENCY_SYMBOLID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

DISPLAYID_LIMIT

public static final int DISPLAYID_LIMIT

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

INTEGER

public static final int INTEGER

Deprecated: This API is ICU internal only.

Number Format types

UNKNOWN:

KEYWORDID

public static final int KEYWORDID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

KEYWORD_VALUEID

public static final int KEYWORD_VALUEID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

LANGUAGEID

public static final int LANGUAGEID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

LOCALEID

public static final int LOCALEID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

NONE

public static final int NONE

Deprecated: This API is ICU internal only.

Supplement to DateFormat.FULL, LONG, MEDIUM, SHORT. Indicates that no value for one of date or time is to be used.

UNKNOWN:

NUMBER

public static final int NUMBER

Deprecated: This API is ICU internal only.

Number Format types

UNKNOWN:

NUMBER_LIMIT

public static final int NUMBER_LIMIT

Deprecated: This API is ICU internal only.

Number Format types

UNKNOWN:

PERCENT

public static final int PERCENT

Deprecated: This API is ICU internal only.

Number Format types

UNKNOWN:

SCIENTIFIC

public static final int SCIENTIFIC

Deprecated: This API is ICU internal only.

Number Format types

UNKNOWN:

SCRIPTID

public static final int SCRIPTID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

TERRITORYID

public static final int TERRITORYID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

TIMEZONEID

public static final int TIMEZONEID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

VARIANTID

public static final int VARIANTID

Deprecated: This API is ICU internal only.

For selecting a choice of display names

UNKNOWN:

Method Detail

cloneAsThawed

public Object cloneAsThawed()

Deprecated: This API is ICU internal only.

UNKNOWN:

freeze

public Object freeze()

Deprecated: This API is ICU internal only.

UNKNOWN:

getCalendar

public Calendar getCalendar()

Deprecated: This API is ICU internal only.

Get a copy of the calendar according to the settings.

Returns: calendar explicit or implicit.

UNKNOWN:

getCollator

public Collator getCollator()

Deprecated: This API is ICU internal only.

Get a copy of the collator according to the settings.

Returns: collator explicit or implicit.

UNKNOWN:

getCurrency

public Currency getCurrency()

Deprecated: This API is ICU internal only.

Get a copy of the currency computed according to the settings.

Returns: currency code, explicit or implicit.

UNKNOWN:

getDateFormat

public DateFormat getDateFormat(int dateStyle, int timeStyle)

Deprecated: This API is ICU internal only.

Gets a date format according to the current settings. If there is an explicit (non-null) date/time format set, a copy of that is returned. Otherwise, if there is a non-null date locale, that is used. Otherwise, the language priority list is used. NONE should be used for the style, where only the date or time format individually is being gotten.

Parameters: dateStyle NONE, or DateFormat.FULL, LONG, MEDIUM, SHORT timeStyle NONE, or DateFormat.FULL, LONG, MEDIUM, SHORT

Returns: a DateFormat, according to the above description

UNKNOWN:

getDateLocale

public ULocale getDateLocale()

Deprecated: This API is ICU internal only.

Gets the date locale, to be used in computing date formats. Overrides the general locale setting.

Returns: date locale. Null if none was set explicitly.

UNKNOWN:

getDisplayName

public String getDisplayName(String id, int type)

Deprecated: This API is ICU internal only.

Get the display name for an ID: language, script, territory, currency, timezone... Uses the language priority list to do so.

Parameters: id language code, script code, ... type specifies the type of the ID: LANGUAGE, etc.

Returns: the display name

UNKNOWN:

getLocale

public ULocale getLocale(int index)

Deprecated: This API is ICU internal only.

Convenience function for getting the locales in priority order

Parameters: index The index (0..n) of the desired item.

Returns: desired item.

UNKNOWN:

getLocales

public List getLocales()

Deprecated: This API is ICU internal only.

Get a copy of the language/locale priority list

Returns: a copy of the language/locale priority list.

UNKNOWN:

getNumberFormat

public NumberFormat getNumberFormat(int style)

Deprecated: This API is ICU internal only.

Gets a number format according to the current settings. If there is an explicit (non-null) number format set, a copy of that is returned. Otherwise, if there is a non-null number locale, that is used. Otherwise, the language priority list is used. NONE should be used for the style, where only the date or time format individually is being gotten.

Parameters: style CURRENCY, NUMBER, INTEGER, SCIENTIFIC, PERCENT

UNKNOWN:

getNumberLocale

public ULocale getNumberLocale()

Deprecated: This API is ICU internal only.

Get the current number locale setting used for getNumberFormat.

Returns: number locale. Null if none was set explicitly.

UNKNOWN:

getTerritory

public String getTerritory()

Deprecated: This API is ICU internal only.

Gets the territory setting. If it wasn't explicitly set, it is computed from the general locale setting.

Returns: territory code, explicit or implicit.

UNKNOWN:

getTimeZone

public TimeZone getTimeZone()

Deprecated: This API is ICU internal only.

Get the timezone. It was either explicitly set, or is heuristically computed from other settings.

Returns: timezone, either implicitly or explicitly set

UNKNOWN:

guessCalendar

protected Calendar guessCalendar()

Deprecated: This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics. It MUST return a 'safe' value, one whose modification will not affect this object.

UNKNOWN:

guessCollator

protected Collator guessCollator()

Deprecated: This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics. It MUST return a 'safe' value, one whose modification will not affect this object.

UNKNOWN:

guessCurrency

protected Currency guessCurrency()

Deprecated: This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics

UNKNOWN:

guessLocales

protected List guessLocales()

Deprecated: This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics It MUST return a 'safe' value, one whose modification will not affect this object.

UNKNOWN:

guessTerritory

protected String guessTerritory()

Deprecated: This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics.

UNKNOWN:

guessTimeZone

protected TimeZone guessTimeZone()

Deprecated: This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics. It MUST return a 'safe' value, one whose modification will not affect this object.

UNKNOWN:

isFrozen

public boolean isFrozen()

Deprecated: This API is ICU internal only.

UNKNOWN:

reset

public GlobalizationPreferences reset()

Deprecated: This API is ICU internal only.

Restore the object to the initial state.

Returns: this, for chaining

UNKNOWN:

setCalendar

public GlobalizationPreferences setCalendar(Calendar calendar)

Deprecated: This API is ICU internal only.

Sets the calendar. If this has not been set, uses default for territory.

Parameters: calendar arbitrary calendar

Returns: this, for chaining

UNKNOWN:

setCollator

public GlobalizationPreferences setCollator(Collator collator)

Deprecated: This API is ICU internal only.

Explicitly set the collator for this object.

Parameters: collator

Returns: this, for chaining

UNKNOWN:

setCurrency

public GlobalizationPreferences setCurrency(Currency currency)

Deprecated: This API is ICU internal only.

Sets the currency code. If this has not been set, uses default for territory.

Parameters: currency Valid ISO 4217 currency code.

Returns: this, for chaining

UNKNOWN:

setDateFormat

public GlobalizationPreferences setDateFormat(int dateStyle, int timeStyle, DateFormat format)

Deprecated: This API is ICU internal only.

Set an explicit date format. Overrides both the date locale, and the locale priority list for a particular combination of dateStyle and timeStyle. NONE should be used if for the style, where only the date or time format individually is being set.

Parameters: dateStyle NONE, or DateFormat.FULL, LONG, MEDIUM, SHORT timeStyle NONE, or DateFormat.FULL, LONG, MEDIUM, SHORT format

Returns: this, for chaining

UNKNOWN:

setDateFormat

public GlobalizationPreferences setDateFormat(int dateStyle, int timeStyle, String formatPattern)

Deprecated: This API is ICU internal only.

Set an explicit date format. Overrides both the date locale, and the locale priority list for a particular combination of dateStyle and timeStyle. NONE should be used if for the style, where only the date or time format individually is being set.

Parameters: dateStyle NONE, or DateFormat.FULL, LONG, MEDIUM, SHORT timeStyle NONE, or DateFormat.FULL, LONG, MEDIUM, SHORT formatPattern date pattern, eg "yyyy-MMM-dd"

Returns: this, for chaining

UNKNOWN:

setDateLocale

public GlobalizationPreferences setDateLocale(ULocale dateLocale)
Set the date locale.

Parameters: dateLocale If not null, overrides the locale priority list for all the date formats.

Returns: this, for chaining

setLocale

public GlobalizationPreferences setLocale(ULocale uLocale)

Deprecated: This API is ICU internal only.

Convenience routine for setting the language/locale priority list from a single locale/language.

Parameters: uLocale single locale

Returns: this, for chaining

See Also: GlobalizationPreferences

UNKNOWN:

setLocales

public GlobalizationPreferences setLocales(List locales)

Deprecated: This API is ICU internal only.

Sets the language/locale priority list. If other information is not (yet) available, this is used to to produce a default value for the appropriate territory, currency, timezone, etc. The user should be given the opportunity to correct those defaults in case they are incorrect.

Parameters: locales list of locales in priority order, eg {"be", "fr"} for Breton first, then French if that fails.

Returns: this, for chaining

UNKNOWN:

setLocales

public GlobalizationPreferences setLocales(ULocale[] uLocales)

Deprecated: This API is ICU internal only.

Convenience routine for setting the language/locale priority list from an array.

Parameters: uLocales list of locales in an array

Returns: this, for chaining

See Also: GlobalizationPreferences

UNKNOWN:

setLocales

public GlobalizationPreferences setLocales(String acceptLanguageString)

Deprecated: This API is ICU internal only.

Convenience routine for setting the locale priority list from an Accept-Language string.

Parameters: acceptLanguageString Accept-Language list, as defined by Section 14.4 of the RFC 2616 (HTTP 1.1)

Returns: this, for chaining

See Also: GlobalizationPreferences

UNKNOWN:

setNumberFormat

public GlobalizationPreferences setNumberFormat(int style, DateFormat format)

Deprecated: This API is ICU internal only.

Sets a number format explicitly. Overrides the number locale and the general locale settings.

Parameters: style CURRENCY, NUMBER, INTEGER, SCIENTIFIC, PERCENT

Returns: this, for chaining

UNKNOWN:

setNumberFormat

public GlobalizationPreferences setNumberFormat(int style, String formatPattern)

Deprecated: This API is ICU internal only.

Sets a number format explicitly. Overrides the number locale and the general locale settings.

Returns: this, for chaining

UNKNOWN:

setNumberLocale

public GlobalizationPreferences setNumberLocale(ULocale numberLocale)

Deprecated: This API is ICU internal only.

Set the number locale.

Parameters: numberLocale If not null, overrides the locale priority list for all the date formats.

Returns: this, for chaining

UNKNOWN:

setTerritory

public GlobalizationPreferences setTerritory(String territory)

Deprecated: This API is ICU internal only.

Sets the territory, which is a valid territory according to for RFC 3066 (or successor). If not otherwise set, default currency and timezone values will be set from this. The user should be given the opportunity to correct those defaults in case they are incorrect.

Parameters: territory code

Returns: this, for chaining

UNKNOWN:

setTimeZone

public GlobalizationPreferences setTimeZone(TimeZone timezone)

Deprecated: This API is ICU internal only.

Sets the timezone ID. If this has not been set, uses default for territory.

Parameters: timezone a valid TZID (see UTS#35).

Returns: this, for chaining

UNKNOWN: