Class LanguageCache
- java.lang.Object
-
- com.helger.commons.locale.language.LanguageCache
-
- All Implemented Interfaces:
IHasConditionalLogger
@ThreadSafe @Singleton public final class LanguageCache extends Object implements IHasConditionalLogger
This is a global cache for language objects to avoid too many objects flowing around.
This cache is application independent.- Since:
- v9.1.3
- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsLanguage(String sLanguage)Check if the passed language is known.booleancontainsLanguage(Locale aLanguage)Check if the passed language is known.ICommonsSet<Locale>getAllLanguageLocales()ICommonsSet<String>getAllLanguages()static LanguageCachegetInstance()LocalegetLanguage(String sLanguage)Resolve the language from the provided string.
Note: this method may be invoked recursively, if the language code contains a locale separator char.LocalegetLanguage(Locale aLanguage)The normed language locale associated with the provided locale.LocalegetLanguageExt(String sLanguage, LocaleCache.IMissingLocaleHandler aMissingHandler)Resolve the language from the provided string.
Note: this method may be invoked recursively, if the language code contains a locale separator char.LocalegetLanguageExt(Locale aLanguage, LocaleCache.IMissingLocaleHandler aMissingHandler)The normed language locale associated with the provided locale.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 LanguageCache getInstance()
-
getLanguage
@Nullable public Locale getLanguage(@Nullable Locale aLanguage)
The normed language locale associated with the provided locale.- Parameters:
aLanguage- Source locale. May benull.- Returns:
nullif the source locale isnullor if the source locale does not contain language information.
-
getLanguageExt
@Nullable public Locale getLanguageExt(@Nullable Locale aLanguage, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler)
The normed language locale associated with the provided locale.- Parameters:
aLanguage- Source locale. May benull.aMissingHandler- The missing locale handler to be passed toLocaleCache. May benullto useLocaleCachedefault handler.- Returns:
nullif the source locale isnullor if the source locale does not contain language information.- Since:
- 9.4.2
-
getLanguage
@Nullable public Locale getLanguage(@Nullable String sLanguage)
Resolve the language from the provided string.
Note: this method may be invoked recursively, if the language code contains a locale separator char.- Parameters:
sLanguage- The language code. May benullor empty.- Returns:
nullif the provided language code isnullor empty.
-
getLanguageExt
@Nullable public Locale getLanguageExt(@Nullable String sLanguage, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler)
Resolve the language from the provided string.
Note: this method may be invoked recursively, if the language code contains a locale separator char.- Parameters:
sLanguage- The language code. May benullor empty.aMissingHandler- The missing locale handler to be passed toLocaleCache. May benullto useLocaleCachedefault handler.- Returns:
nullif the provided language code isnullor empty.- Since:
- 9.4.2
-
getAllLanguages
@Nonnull @ReturnsMutableCopy public ICommonsSet<String> getAllLanguages()
- Returns:
- a set with all contained languages. Never
null.
-
getAllLanguageLocales
@Nonnull @ReturnsMutableCopy public ICommonsSet<Locale> getAllLanguageLocales()
- Returns:
- a set with all contained language locales. Never
null.
-
containsLanguage
public boolean containsLanguage(@Nullable Locale aLanguage)
Check if the passed language is known.- Parameters:
aLanguage- The language to check. May benull.- Returns:
trueif the passed language is contained,falseotherwise.
-
containsLanguage
public boolean containsLanguage(@Nullable String sLanguage)
Check if the passed language is known.- Parameters:
sLanguage- The language to check. May benull.- Returns:
trueif the passed language is contained,falseotherwise.
-
reinitialize
public void reinitialize()
Reset the cache to the initial state.
-
-