Class CountryCache
- java.lang.Object
-
- com.helger.commons.locale.country.CountryCache
-
- All Implemented Interfaces:
IHasConditionalLogger
@ThreadSafe @Singleton public class CountryCache extends Object implements IHasConditionalLogger
This is a global cache for country objects to avoid too many object flowing around.
This cache is application independent.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCountryCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsCountry(String sCountry)Check if the passed country is known.booleancontainsCountry(Locale aCountry)Check if the passed country is known.ICommonsSet<String>getAllCountries()ICommonsSet<Locale>getAllCountryLocales()LocalegetCountry(String sCountry)Resolve the country from the provided string.
Note: this method may be invoked recursively, if the country code contains a locale separator char.LocalegetCountry(Locale aCountry)The normed country locale associated with the provided locale.LocalegetCountryExt(String sCountry, LocaleCache.IMissingLocaleHandler aMissingHandler)Resolve the country from the provided string.
Note: this method may be invoked recursively, if the country code contains a locale separator char.LocalegetCountryExt(Locale aCountry, LocaleCache.IMissingLocaleHandler aMissingHandler)The normed country locale associated with the provided locale.static CountryCachegetInstance()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 CountryCache getInstance()
- Returns:
- The one and only global instances. Never
null.
-
getCountry
@Nullable public Locale getCountry(@Nullable Locale aCountry)
The normed country locale associated with the provided locale.- Parameters:
aCountry- Source locale. May benull.- Returns:
nullif the source locale isnullor if the source locale does not contain country information.
-
getCountryExt
@Nullable public Locale getCountryExt(@Nullable Locale aCountry, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler)
The normed country locale associated with the provided locale.- Parameters:
aCountry- 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 country information.- Since:
- 9.4.2
-
getCountry
@Nullable public Locale getCountry(@Nullable String sCountry)
Resolve the country from the provided string.
Note: this method may be invoked recursively, if the country code contains a locale separator char.- Parameters:
sCountry- The country code. May benullor empty.- Returns:
nullif the provided country code isnullor empty.
-
getCountryExt
@Nullable public Locale getCountryExt(@Nullable String sCountry, @Nullable LocaleCache.IMissingLocaleHandler aMissingHandler)
Resolve the country from the provided string.
Note: this method may be invoked recursively, if the country code contains a locale separator char.- Parameters:
sCountry- The country code. May benullor empty.aMissingHandler- The missing locale handler to be passed toLocaleCache. May benullto useLocaleCachedefault handler.- Returns:
nullif the provided country code isnullor empty.- Since:
- 9.4.2
-
getAllCountries
@Nonnull @ReturnsMutableCopy public ICommonsSet<String> getAllCountries()
- Returns:
- a set with all contained countries. Never
null.
-
getAllCountryLocales
@Nonnull @ReturnsMutableCopy public ICommonsSet<Locale> getAllCountryLocales()
- Returns:
- a set with all contained country locales. Never
null.
-
containsCountry
public boolean containsCountry(@Nullable Locale aCountry)
Check if the passed country is known.- Parameters:
aCountry- The country to check. May benull.- Returns:
trueif the passed country is contained,falseotherwise.
-
containsCountry
public boolean containsCountry(@Nullable String sCountry)
Check if the passed country is known.- Parameters:
sCountry- The country to check. May benull.- Returns:
trueif the passed country is contained,falseotherwise.
-
reinitialize
public final void reinitialize()
Reset the cache to the initial state.
-
-