Package com.iizix

Class LocaleInfo

java.lang.Object
com.iizix.LocaleInfo
All Implemented Interfaces:
Cloneable

public class LocaleInfo extends Object implements 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 Details

    • ENGLISH_LOCALEINFO

      public static final LocaleInfo ENGLISH_LOCALEINFO
      The Locale.ENGLISH based locale info.
    • DEFAULT_LOCALEINFO

      public static final LocaleInfo DEFAULT_LOCALEINFO
      The system default locale info.
  • Method Details

    • getLocaleInfo

      public static LocaleInfo getLocaleInfo(String languageCode)
      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

      public static LocaleInfo getLocaleInfo(Locale locale)
      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

      public static LocaleInfo getLocaleInfo(String country, String language, String variant)
      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. If all parameters are null the current LocaleInfo is returned.
    • setCurrent

      public static void setCurrent(LocaleInfo localeInfo)
      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

      public 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.
      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

      public static LocaleInfo getCurrent(boolean logDefault)
      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

      public LocaleInfo clone()
      Clones the instance.
      Overrides:
      clone in class Object
      Returns:
      A new instance.
    • getLocale

      public Locale getLocale()
      Gets the locale.
      Returns:
      The locale.
    • getCollator

      public Collator 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

      public String getLanguageCode()
      Gets the language code to use.
      Returns:
      The language code, or null for default (not defined by the client).
    • getCurrency

      public Currency getCurrency()
      Gets the currency instance.
      Returns:
      The Currency instance.
    • createNumberFormat

      public NumberFormat createNumberFormat()
      Gets the NumberFormat.
      Returns:
      The NumberFormat for the locale.
    • getDecimalFormatSymbols

      public DecimalFormatSymbols getDecimalFormatSymbols()
      Gets the DecimalFormatSymbols object for the locale.
      Returns:
      The decimal format symbols the current locale.
    • createDecimalFormat

      public DecimalFormat 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

      public NumberFormat createIntegerFormat()
      Gets an Integer NumberFormat in the specified locale. The format returned is a cloned cached copy.
      Returns:
      The Integer NumberFormat instance.
    • createPercentFormat

      public NumberFormat createPercentFormat()
      Gets a Percent NumberFormat in the specified locale. The format returned is a cloned cached copy.
      Returns:
      The Percent NumberFormat instance.
    • createCurrencyFormat

      public NumberFormat 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

      public DateTimeFormatter getDateTimeFormatter(FormatStyle style)
      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

      public DateTimeFormatter getDateTimeFormatter(String pattern)
      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

      public int initializeTimeZone(int offset, String name)
      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

      public TimeZone getTimeZone()
      Gets the time-zone.
      Returns:
      The time-zone, if not initialized, the default system time-zone is returned.
    • getZoneId

      public ZoneId getZoneId()
      Gets the time-zone ID.
      Returns:
      The time-zone ID, if not initialized, the default system time-zone ID is returned.
    • getZoneOffset

      public ZoneOffset getZoneOffset()
      Gets the time-zone offset.
      Returns:
      The time-zone offset, if not initialized, the default system time-zone offset is returned.
    • formatTemperature

      public String formatTemperature(double temperature, int decimals, TemperatureUnit unit)
      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

      public String formatTemperature(float temperature, int decimals, TemperatureUnit unit)
      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.