Package com.iizix
Class LocaleInfo
java.lang.Object
com.iizix.LocaleInfo
- All Implemented Interfaces:
Cloneable
The LocaleInfo class contains information of the system-global or client session specific Locale, Currency, NumberFormat, date and time format.
- Author:
- Christopher Mindus
Field Summary
Modifier and TypeFieldDescriptionstatic final LocaleInfo
The system default locale info.static final LocaleInfo
The Locale.ENGLISH based locale info.Method Summary
Modifier and TypeMethodDescriptionclone()
Clones the instance.Gets a Currency NumberFormat in the specified locale with the currency symbols loaded.Gets a default DecimalFormat instance that can be used by cloning to set patterns, etc.Gets an Integer NumberFormat in the specified locale.Gets the NumberFormat.Gets a Percent NumberFormat in the specified locale.formatTemperature
(double temperature, int decimals, TemperatureUnit unit) Converts a temperature to a String.formatTemperature
(float temperature, int decimals, TemperatureUnit unit) Converts a temperature to a String.Gets the collator used for sorting strings for this locale.Gets the currency instance.static LocaleInfo
getCurrent
(boolean logDefault) Gets the current LocalInfo for the calling thread.getDateTimeFormatter
(String pattern) Gets the date and time formatter in this locale of the specified pattern.getDateTimeFormatter
(FormatStyle style) Gets the date and time formatter in this locale of the specified type.Gets the DecimalFormatSymbols object for the locale.Gets the language code to use.Gets the locale.static LocaleInfo
getLocaleInfo
(String languageCode) Creates or gets a cached copy of a locale for a language code.static LocaleInfo
getLocaleInfo
(String country, String language, String variant) Creates or gets a cached copy of a locale for a language.static LocaleInfo
getLocaleInfo
(Locale locale) Creates or gets a cached copy of a locale for a language.static LocaleInfo
getNonNull
(LocaleInfo localeInfo, boolean logDefault) Returns the LocaleInfo from the parameter if non-null, otherwise takes the current user's LocaleInfo or the system's.org.joda.time.format.PeriodFormatter
Gets the period formatter in this locale.Gets the time-zone.Gets the time-zone ID.Gets the time-zone offset.int
initializeTimeZone
(int offset, String name) Initializes the time-zone information.boolean
Returns if the locale is using Default English.static void
setCurrent
(LocaleInfo localeInfo) Sets the current LocaleInfo, i.e.
Field Details
ENGLISH_LOCALEINFO
The Locale.ENGLISH based locale info.DEFAULT_LOCALEINFO
The system default locale info.
Method Details
getLocaleInfo
Creates or gets a cached copy of a locale for a language code.- Parameters:
languageCode
- The language code.- Returns:
- The LocaleInfo for the parameters.
getLocaleInfo
Creates or gets a cached copy of a locale for a language.- Parameters:
locale
- The locale, non-null.- Returns:
- A cloned LocaleInfo from a cached instance for the locale in question.
getLocaleInfo
Creates or gets a cached copy of a locale for a language.- Parameters:
country
- The country.language
- The language.variant
- The variant.- Returns:
- The LocaleInfo for the parameters.
setCurrent
Sets the current LocaleInfo, i.e. for the Designer. This method throws IllegalStateException if executing elsewhere that in the Designer.- Parameters:
localeInfo
- The default locale information.- Throws:
IllegalStateException
- When called and the Designer is not the calling process.
getNonNull
Returns the LocaleInfo from the parameter if non-null, otherwise takes the current user's LocaleInfo or the system's.- Parameters:
localeInfo
- The locale information, or null.logDefault
- Flag indicating a warning message is logged if the default is used due to none other LocaleInfo found.- Returns:
- The
localeInfo
parameter is non-null, otherwise the user's or system locale information.
getCurrent
Gets the current LocalInfo for the calling thread. This value is extracted from the Thread context depending on where it is executing (i.e. Server, Designer, etc). If none is found, the default LocaleInfo is returned.- Parameters:
logDefault
- Flag indicating a warning message is logged if the default is used due to none other LocaleInfo found.- Returns:
- A LocaleInfo instance.
clone
Clones the instance.getLocale
Gets the locale.- Returns:
- The locale.
getCollator
Gets the collator used for sorting strings for this locale.- Returns:
- The collator.
isDefaultEnglish
public boolean isDefaultEnglish()Returns if the locale is using Default English.- Returns:
- true if language is English.
getLanguageCode
Gets the language code to use.- Returns:
- The language code, or null for default (not defined by the client).
getCurrency
Gets the currency instance.- Returns:
- The Currency instance.
createNumberFormat
Gets the NumberFormat.- Returns:
- The NumberFormat for the locale.
getDecimalFormatSymbols
Gets the DecimalFormatSymbols object for the locale.- Returns:
- The decimal format symbols the current locale.
createDecimalFormat
Gets a default DecimalFormat instance that can be used by cloning to set patterns, etc. The format returned is a cloned cached copy.- Returns:
- The DecimalFormat instance initialized with the current locale's DecimalFormatSymbols.
createIntegerFormat
Gets an Integer NumberFormat in the specified locale. The format returned is a cloned cached copy.- Returns:
- The Integer NumberFormat instance.
createPercentFormat
Gets a Percent NumberFormat in the specified locale. The format returned is a cloned cached copy.- Returns:
- The Percent NumberFormat instance.
createCurrencyFormat
Gets a Currency NumberFormat in the specified locale with the currency symbols loaded. The format returned is a cloned cached copy.- Returns:
- The Currency NumberFormat instance.
getDateTimeFormatter
Gets the date and time formatter in this locale of the specified type.- Parameters:
style
- The format style.- Returns:
- A cached formatter.
- See Also:
getDateTimeFormatter
Gets the date and time formatter in this locale of the specified pattern.- Parameters:
pattern
- The pattern.- Returns:
- A formatter.
- See Also:
getPeriodFormatter
public org.joda.time.format.PeriodFormatter getPeriodFormatter()Gets the period formatter in this locale.- Returns:
- The Joda PeriodFormatter instance for the locale.
initializeTimeZone
Initializes the time-zone information. This method is not intended to be called, it is done by the framework.The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead.
- Parameters:
offset
- In minutes.name
- The time-zone name in the form "{area}/{city}", e.g. "Europe/Berlin", null or empty for none.- Returns:
- -1 for invalid offset, 0=success, 1 for unknown zone name but success. Any problems with offset or name are logged as warnings.
getTimeZone
Gets the time-zone.- Returns:
- The time-zone, if not initialized, the default system time-zone is returned.
getZoneId
Gets the time-zone ID.- Returns:
- The time-zone ID, if not initialized, the default system time-zone ID is returned.
getZoneOffset
Gets the time-zone offset.- Returns:
- The time-zone offset, if not initialized, the default system time-zone offset is returned.
formatTemperature
Converts a temperature to a String.- Parameters:
temperature
- The temperature value.decimals
- The number of decimals (zero or more).unit
- The temperature unit.- Returns:
- The String formatted as e.g. "1234,45 °F" for Fahrenheit.
formatTemperature
Converts a temperature to a String.- Parameters:
temperature
- The temperature value.decimals
- The number of decimals (zero or more).unit
- The temperature unit.- Returns:
- The String formatted as e.g. "1234,45 °F" for Fahrenheit.