Class LocaleCache

java.lang.Object
com.helger.commons.locale.LocaleCache
All Implemented Interfaces:
IHasConditionalLogger

@ThreadSafe @Singleton public class LocaleCache extends Object implements IHasConditionalLogger
This is a global cache for Locale objects to avoid too many object flowing around.
This cache is application independent.
Author:
Philip Helger
  • Constructor Details

    • LocaleCache

      protected LocaleCache()
  • Method Details

    • isSilentMode

      public static boolean isSilentMode()
      Returns:
      true if logging is disabled, false if it is enabled.
      Since:
      9.4.0
    • setSilentMode

      public static boolean setSilentMode(boolean bSilentMode)
      Enable or disable certain regular log messages.
      Parameters:
      bSilentMode - true to disable logging, false to enable logging
      Returns:
      The previous value of the silent mode.
      Since:
      9.4.0
    • isInstantiated

      public static boolean isInstantiated()
    • getInstance

      @Nonnull public static LocaleCache getInstance()
    • getDefaultMissingLocaleHandler

      @Nonnull public final LocaleCache.IMissingLocaleHandler getDefaultMissingLocaleHandler()
      Returns:
      The LocaleCache.IMissingLocaleHandler implementation of this instance that adds a missing locale to the set. Never null.
      Since:
      9.4.2
    • getLocale

      @Nullable public Locale getLocale(@Nullable String sLanguage)
      Get the Locale object matching the given language.
      Parameters:
      sLanguage - The language to use. May be null or empty.
      Returns:
      null if the passed language string is null or empty
    • getLocaleExt

      @Nullable public Locale getLocaleExt(@Nullable String sLanguage, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler)
      Get the Locale object matching the given language.
      Parameters:
      sLanguage - The language to use. May be null or empty.
      aMissingHandler - An optional handler to be invoked if the provided locale is not yet contained. May be null.
      Returns:
      null if the passed language string is null or empty
      Since:
      9.3.9
    • getLocale

      @Nullable public Locale getLocale(@Nullable String sLanguage, @Nullable String sCountry)
      Get the Locale object matching the given language and country.
      Parameters:
      sLanguage - The language to use. May be null or empty.
      sCountry - The country to use. May be null.
      Returns:
      null if the passed language string is null or empty
    • getLocale

      @Nullable public Locale getLocale(@Nullable String sLanguage, @Nullable String sCountry, @Nullable String sVariant)
      Get the Locale object matching the given locale string
      Parameters:
      sLanguage - The language to use. May be null or empty.
      sCountry - Optional country to use. May be null.
      sVariant - Optional variant. May be null.
      Returns:
      null if all the passed parameters are null or empty
    • getLocale

      @Nullable public Locale getLocale(@Nullable String sLanguage, @Nullable String sCountry, @Nullable String sVariant, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler)
      Get the Locale object matching the given locale string
      Parameters:
      sLanguage - The language to use. May be null or empty.
      sCountry - Optional country to use. May be null.
      sVariant - Optional variant. May be null.
      aMissingHandler - An optional handler to be invoked if the provided locale is not yet contained. May be null.
      Returns:
      null if all the passed parameters are null or empty
      Since:
      9.3.9
    • getAllLocales

      Get all contained locales except the locales "all" and "independent"
      Returns:
      a set with all contained locales, except "all" and "independent". Never null.
    • getAllLanguages

      @Nonnull @ReturnsMutableCopy public ICommonsSet<Locale> getAllLanguages()
      Get all contained locales that consist only of a non-empty language.
      Returns:
      a set with all contained languages, except "all" and "independent"
    • containsLocale

      public boolean containsLocale(@Nullable String sLanguage)
      Check if the passed language is in the cache.
      Parameters:
      sLanguage - The language to check.
      Returns:
      true if it is in the cache, false otherwise.
    • containsLocale

      public boolean containsLocale(@Nullable String sLanguage, @Nullable String sCountry)
      Check if the passed language is in the cache.
      Parameters:
      sLanguage - The language to check.
      sCountry - The country to check.
      Returns:
      true if it is in the cache, false otherwise.
    • containsLocale

      public boolean containsLocale(@Nullable String sLanguage, @Nullable String sCountry, @Nullable String sVariant)
      Check if the passed language is in the cache.
      Parameters:
      sLanguage - The language to check.
      sCountry - The country to check.
      sVariant - The variant to check.
      Returns:
      true if it is in the cache, false otherwise.
    • getAllDefaultLocales

      @Nonnull @ReturnsMutableCopy public static ICommonsOrderedSet<Locale> getAllDefaultLocales()
      Returns:
      A set of all system default locales. Never null.
    • reinitialize

      public final void reinitialize()
      Reset the cache to the initial state.