Class 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 Detail

      • CountryCache

        protected CountryCache()
    • Method Detail

      • 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 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 be null.
        Returns:
        null if the source locale is null or 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 be null.
        aMissingHandler - The missing locale handler to be passed to LocaleCache. May be null to use LocaleCache default handler.
        Returns:
        null if the source locale is null or 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 be null or empty.
        Returns:
        null if the provided country code is null or 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 be null or empty.
        aMissingHandler - The missing locale handler to be passed to LocaleCache. May be null to use LocaleCache default handler.
        Returns:
        null if the provided country code is null or empty.
        Since:
        9.4.2
      • containsCountry

        public boolean containsCountry​(@Nullable
                                       Locale aCountry)
        Check if the passed country is known.
        Parameters:
        aCountry - The country to check. May be null.
        Returns:
        true if the passed country is contained, false otherwise.
      • containsCountry

        public boolean containsCountry​(@Nullable
                                       String sCountry)
        Check if the passed country is known.
        Parameters:
        sCountry - The country to check. May be null.
        Returns:
        true if the passed country is contained, false otherwise.
      • reinitialize

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