com.ibm.icu.util

Class GlobalizationPreferences

Implemented Interfaces:
Cloneable, Freezable

public class GlobalizationPreferences
extends Object
implements Freezable

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:

Field Summary

static int
CURRENCY
Deprecated. This API is ICU internal only.
static int
CURRENCYID
Deprecated. This API is ICU internal only.
static int
CURRENCY_SYMBOLID
Deprecated. This API is ICU internal only.
static int
DISPLAYID_LIMIT
Deprecated. This API is ICU internal only.
static int
INTEGER
Deprecated. This API is ICU internal only.
static int
KEYWORDID
Deprecated. This API is ICU internal only.
static int
KEYWORD_VALUEID
Deprecated. This API is ICU internal only.
static int
LANGUAGEID
Deprecated. This API is ICU internal only.
static int
LOCALEID
Deprecated. This API is ICU internal only.
static int
NONE
Deprecated. This API is ICU internal only.
static int
NUMBER
Deprecated. This API is ICU internal only.
static int
NUMBER_LIMIT
Deprecated. This API is ICU internal only.
static int
PERCENT
Deprecated. This API is ICU internal only.
static int
SCIENTIFIC
Deprecated. This API is ICU internal only.
static int
SCRIPTID
Deprecated. This API is ICU internal only.
static int
TERRITORYID
Deprecated. This API is ICU internal only.
static int
TIMEZONEID
Deprecated. This API is ICU internal only.
static int
VARIANTID
Deprecated. This API is ICU internal only.

Method Summary

Object
cloneAsThawed()
Deprecated. This API is ICU internal only.
Object
freeze()
Deprecated. This API is ICU internal only.
Calendar
getCalendar()
Deprecated. This API is ICU internal only.
Collator
getCollator()
Deprecated. This API is ICU internal only.
Currency
getCurrency()
Deprecated. This API is ICU internal only.
DateFormat
getDateFormat(int dateStyle, int timeStyle)
Deprecated. This API is ICU internal only.
ULocale
getDateLocale()
Deprecated. This API is ICU internal only.
String
getDisplayName(String id, int type)
Deprecated. This API is ICU internal only.
ULocale
getLocale(int index)
Deprecated. This API is ICU internal only.
List
getLocales()
Deprecated. This API is ICU internal only.
NumberFormat
getNumberFormat(int style)
Deprecated. This API is ICU internal only.
ULocale
getNumberLocale()
Deprecated. This API is ICU internal only.
String
getTerritory()
Deprecated. This API is ICU internal only.
TimeZone
getTimeZone()
Deprecated. This API is ICU internal only.
protected Calendar
guessCalendar()
Deprecated. This API is ICU internal only.
protected Collator
guessCollator()
Deprecated. This API is ICU internal only.
protected Currency
guessCurrency()
Deprecated. This API is ICU internal only.
protected List
guessLocales()
Deprecated. This API is ICU internal only.
protected String
guessTerritory()
Deprecated. This API is ICU internal only.
protected TimeZone
guessTimeZone()
Deprecated. This API is ICU internal only.
boolean
isFrozen()
Deprecated. This API is ICU internal only.
GlobalizationPreferences
reset()
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setCalendar(Calendar calendar)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setCollator(Collator collator)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setCurrency(Currency currency)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setDateFormat(int dateStyle, int timeStyle, String formatPattern)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setDateFormat(int dateStyle, int timeStyle, DateFormat format)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setDateLocale(ULocale dateLocale)
Set the date locale.
GlobalizationPreferences
setLocale(ULocale uLocale)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setLocales(List locales)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setLocales(String acceptLanguageString)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setLocales(ULocale[] uLocales)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setNumberFormat(int style, String formatPattern)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setNumberFormat(int style, DateFormat format)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setNumberLocale(ULocale numberLocale)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setTerritory(String territory)
Deprecated. This API is ICU internal only.
GlobalizationPreferences
setTimeZone(TimeZone timezone)
Deprecated. This API is ICU internal only.

Field Details

CURRENCY

public static final int CURRENCY

Deprecated. This API is ICU internal only.

Number Format types
Field Value:
0

CURRENCYID

public static final int CURRENCYID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
7

CURRENCY_SYMBOLID

public static final int CURRENCY_SYMBOLID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
8

DISPLAYID_LIMIT

public static final int DISPLAYID_LIMIT

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
10

INTEGER

public static final int INTEGER

Deprecated. This API is ICU internal only.

Number Format types
Field Value:
2

KEYWORDID

public static final int KEYWORDID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
5

KEYWORD_VALUEID

public static final int KEYWORD_VALUEID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
6

LANGUAGEID

public static final int LANGUAGEID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
1

LOCALEID

public static final int LOCALEID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
0

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.
Field Value:
4

NUMBER

public static final int NUMBER

Deprecated. This API is ICU internal only.

Number Format types
Field Value:
1

NUMBER_LIMIT

public static final int NUMBER_LIMIT

Deprecated. This API is ICU internal only.

Number Format types
Field Value:
5

PERCENT

public static final int PERCENT

Deprecated. This API is ICU internal only.

Number Format types
Field Value:
4

SCIENTIFIC

public static final int SCIENTIFIC

Deprecated. This API is ICU internal only.

Number Format types
Field Value:
3

SCRIPTID

public static final int SCRIPTID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
2

TERRITORYID

public static final int TERRITORYID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
3

TIMEZONEID

public static final int TIMEZONEID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
9

VARIANTID

public static final int VARIANTID

Deprecated. This API is ICU internal only.

For selecting a choice of display names
Field Value:
4

Method Details

cloneAsThawed

public Object cloneAsThawed()

Deprecated. This API is ICU internal only.

Specified by:
cloneAsThawed in interface Freezable

freeze

public Object freeze()

Deprecated. This API is ICU internal only.

Specified by:
freeze in interface Freezable

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.

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.

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.

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

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.

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

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.

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.

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

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.

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.

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

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.

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.

guessCurrency

protected Currency guessCurrency()

Deprecated. This API is ICU internal only.

This function can be overridden by subclasses to use different heuristics

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.

guessTerritory

protected String guessTerritory()

Deprecated. This API is ICU internal only.

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

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.

isFrozen

public boolean isFrozen()

Deprecated. This API is ICU internal only.

Specified by:
isFrozen in interface Freezable

reset

public GlobalizationPreferences reset()

Deprecated. This API is ICU internal only.

Restore the object to the initial state.
Returns:
this, for chaining

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

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

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

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

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

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:
setLocales(List locales)

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

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:
setLocales(List locales)

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:
setLocales(List locales)

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

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

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

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

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

Copyright (c) 2006 IBM Corporation and others.