Package com.iizix

Class LocaleInfo

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class LocaleInfo
    extends java.lang.Object
    implements java.lang.Cloneable
    The LocaleInfo class contains information of the system-global or client session specific Locale, Currency, NumberFormat, date and time format.
    Author:
    Christopher Mindus
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      LocaleInfo clone()
      Clones the instance.
      java.text.NumberFormat createCurrencyFormat()
      Gets a Currency NumberFormat in the specified locale with the currency symbols loaded.
      java.text.DecimalFormat createDecimalFormat()
      Gets a default DecimalFormat instance that can be used by cloning to set patterns, etc.
      java.text.NumberFormat createIntegerFormat()
      Gets an Integer NumberFormat in the specified locale.
      java.text.NumberFormat createNumberFormat()
      Gets the NumberFormat.
      java.text.NumberFormat createPercentFormat()
      Gets a Percent NumberFormat in the specified locale.
      java.text.Collator getCollator()
      Gets the collator used for sorting strings for this locale.
      java.util.Currency getCurrency()
      Gets the currency instance.
      static LocaleInfo getCurrent​(boolean logDefault)
      Gets the current LocalInfo for the calling thread.
      java.time.format.DateTimeFormatter getDateTimeFormatter​(java.lang.String pattern)
      Gets the date and time formatter in this locale of the specified pattern.
      java.time.format.DateTimeFormatter getDateTimeFormatter​(java.time.format.FormatStyle style)
      Gets the date and time formatter in this locale of the specified type.
      java.text.DecimalFormatSymbols getDecimalFormatSymbols()
      Gets the DecimalFormatSymbols object for the locale.
      java.lang.String getLanguageCode()
      Gets the language code to use.
      java.util.Locale getLocale()
      Gets the locale.
      static LocaleInfo getLocaleInfo​(java.lang.String languageCode)
      Creates or gets a cached copy of a locale for a language code.
      static LocaleInfo getLocaleInfo​(java.lang.String country, java.lang.String language, java.lang.String variant)
      Creates or gets a cached copy of a locale for a language.
      static LocaleInfo getLocaleInfo​(java.util.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 getPeriodFormatter()
      Gets the period formatter in this locale.
      java.util.TimeZone getTimeZone()
      Gets the time-zone.
      java.time.ZoneId getZoneId()
      Gets the time-zone ID.
      java.time.ZoneOffset getZoneOffset()
      Gets the time-zone offset.
      int initializeTimeZone​(int offset, java.lang.String name)
      Initializes the time-zone information.
      boolean isDefaultEnglish()
      Returns if the locale is using Default English.
      static void setCurrent​(LocaleInfo localeInfo)
      Sets the current LocaleInfo, i.e.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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 Detail

      • getLocaleInfo

        public static LocaleInfo getLocaleInfo​(java.lang.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​(java.util.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​(java.lang.String country,
                                               java.lang.String language,
                                               java.lang.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.
      • 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:
        java.lang.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 java.lang.Object
        Returns:
        A new instance.
      • getLocale

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

        public java.text.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 java.lang.String getLanguageCode()
        Gets the language code to use.
        Returns:
        The language code, or null for default (not defined by the client).
      • getCurrency

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

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

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

        public java.text.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 java.text.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 java.text.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 java.text.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 java.time.format.DateTimeFormatter getDateTimeFormatter​(java.time.format.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:
        For PATTERN_* definitions.
      • getDateTimeFormatter

        public java.time.format.DateTimeFormatter getDateTimeFormatter​(java.lang.String pattern)
        Gets the date and time formatter in this locale of the specified pattern.
        Parameters:
        pattern - The pattern.
        Returns:
        A formatter.
        See Also:
        For PATTERN_* definitions.
      • 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,
                                      java.lang.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 java.util.TimeZone getTimeZone()
        Gets the time-zone.
        Returns:
        The time-zone, if not initialized, the default system time-zone is returned.
      • getZoneId

        public java.time.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 java.time.ZoneOffset getZoneOffset()
        Gets the time-zone offset.
        Returns:
        The time-zone offset, if not initialized, the default system time-zone offset is returned.