Package com.helger.commons.locale
Class LocaleCache
java.lang.Object
com.helger.commons.locale.LocaleCache
- All Implemented Interfaces:
IHasConditionalLogger
This is a global cache for Locale objects to avoid too many object flowing
around.
This cache is application independent.
This cache is application independent.
- Author:
- Philip Helger
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInternal interface for a callback handler to be invoked, if a non-existing locale is found. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsLocale(String sLanguage) Check if the passed language is in the cache.booleancontainsLocale(String sLanguage, String sCountry) Check if the passed language is in the cache.booleancontainsLocale(String sLanguage, String sCountry, String sVariant) Check if the passed language is in the cache.static ICommonsOrderedSet<Locale> Get all contained locales that consist only of a non-empty language.Get all contained locales except the locales "all" and "independent"static LocaleCacheGet theLocaleobject matching the given language.Get theLocaleobject matching the given language and country.Get theLocaleobject matching the given locale stringgetLocale(String sLanguage, String sCountry, String sVariant, LocaleCache.IMissingLocaleHandler aMissingHandler) Get theLocaleobject matching the given locale stringgetLocaleExt(String sLanguage, LocaleCache.IMissingLocaleHandler aMissingHandler) Get theLocaleobject matching the given language.static booleanstatic booleanfinal voidReset the cache to the initial state.static booleansetSilentMode(boolean bSilentMode) Enable or disable certain regular log messages.
-
Constructor Details
-
LocaleCache
protected LocaleCache()
-
-
Method Details
-
isSilentMode
public static boolean isSilentMode()- Returns:
trueif logging is disabled,falseif it is enabled.- Since:
- 9.4.0
-
setSilentMode
public static boolean setSilentMode(boolean bSilentMode) Enable or disable certain regular log messages.- Parameters:
bSilentMode-trueto disable logging,falseto enable logging- Returns:
- The previous value of the silent mode.
- Since:
- 9.4.0
-
isInstantiated
public static boolean isInstantiated() -
getInstance
-
getDefaultMissingLocaleHandler
- Returns:
- The
LocaleCache.IMissingLocaleHandlerimplementation of this instance that adds a missing locale to the set. Nevernull. - Since:
- 9.4.2
-
getLocale
Get theLocaleobject matching the given language.- Parameters:
sLanguage- The language to use. May benullor empty.- Returns:
nullif the passed language string isnullor empty
-
getLocaleExt
@Nullable public Locale getLocaleExt(@Nullable String sLanguage, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler) Get theLocaleobject matching the given language.- Parameters:
sLanguage- The language to use. May benullor empty.aMissingHandler- An optional handler to be invoked if the provided locale is not yet contained. May benull.- Returns:
nullif the passed language string isnullor empty- Since:
- 9.3.9
-
getLocale
Get theLocaleobject matching the given language and country.- Parameters:
sLanguage- The language to use. May benullor empty.sCountry- The country to use. May benull.- Returns:
nullif the passed language string isnullor empty
-
getLocale
@Nullable public Locale getLocale(@Nullable String sLanguage, @Nullable String sCountry, @Nullable String sVariant) Get theLocaleobject matching the given locale string- Parameters:
sLanguage- The language to use. May benullor empty.sCountry- Optional country to use. May benull.sVariant- Optional variant. May benull.- Returns:
nullif all the passed parameters arenullor empty
-
getLocale
@Nullable public Locale getLocale(@Nullable String sLanguage, @Nullable String sCountry, @Nullable String sVariant, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler) Get theLocaleobject matching the given locale string- Parameters:
sLanguage- The language to use. May benullor empty.sCountry- Optional country to use. May benull.sVariant- Optional variant. May benull.aMissingHandler- An optional handler to be invoked if the provided locale is not yet contained. May benull.- Returns:
nullif all the passed parameters arenullor 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
Get all contained locales that consist only of a non-empty language.- Returns:
- a set with all contained languages, except "all" and "independent"
-
containsLocale
Check if the passed language is in the cache.- Parameters:
sLanguage- The language to check.- Returns:
trueif it is in the cache,falseotherwise.
-
containsLocale
Check if the passed language is in the cache.- Parameters:
sLanguage- The language to check.sCountry- The country to check.- Returns:
trueif it is in the cache,falseotherwise.
-
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:
trueif it is in the cache,falseotherwise.
-
getAllDefaultLocales
- Returns:
- A set of all system default locales. Never
null.
-
reinitialize
public final void reinitialize()Reset the cache to the initial state.
-