Package com.helger.commons.locale
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLocaleCache.IMissingLocaleHandlerInternal interface for a callback handler to be invoked, if a non-existing locale is found.
-
Constructor Summary
Constructors Modifier Constructor Description protectedLocaleCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsLocale(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>getAllDefaultLocales()ICommonsSet<Locale>getAllLanguages()Get all contained locales that consist only of a non-empty language.ICommonsList<Locale>getAllLocales()Get all contained locales except the locales "all" and "independent"LocaleCache.IMissingLocaleHandlergetDefaultMissingLocaleHandler()static LocaleCachegetInstance()LocalegetLocale(String sLanguage)Get theLocaleobject matching the given language.LocalegetLocale(String sLanguage, String sCountry)Get theLocaleobject matching the given language and country.LocalegetLocale(String sLanguage, String sCountry, String sVariant)Get theLocaleobject matching the given locale stringLocalegetLocale(String sLanguage, String sCountry, String sVariant, LocaleCache.IMissingLocaleHandler aMissingHandler)Get theLocaleobject matching the given locale stringLocalegetLocaleExt(String sLanguage, LocaleCache.IMissingLocaleHandler aMissingHandler)Get theLocaleobject matching the given language.static booleanisInstantiated()static booleanisSilentMode()voidreinitialize()Reset the cache to the initial state.static booleansetSilentMode(boolean bSilentMode)Enable or disable certain regular log messages.
-
-
-
Method Detail
-
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
@Nonnull public static LocaleCache getInstance()
-
getDefaultMissingLocaleHandler
@Nonnull public final LocaleCache.IMissingLocaleHandler getDefaultMissingLocaleHandler()
- Returns:
- The
LocaleCache.IMissingLocaleHandlerimplementation of this instance that adds a missing locale to the set. Nevernull. - Since:
- 9.4.2
-
getLocale
@Nullable public Locale getLocale(@Nullable String sLanguage)
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
@Nullable public Locale getLocale(@Nullable String sLanguage, @Nullable String sCountry)
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
@Nonnull @ReturnsMutableCopy public ICommonsList<Locale> 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:
trueif it is in the cache,falseotherwise.
-
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:
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
@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.
-
-