Class PluralRulesLoader

    • Field Detail

      • pluralRulesCache

        private final java.util.Map<java.lang.String,​PluralRules> pluralRulesCache
      • localeIdToCardinalRulesId

        private java.util.Map<java.lang.String,​java.lang.String> localeIdToCardinalRulesId
      • localeIdToOrdinalRulesId

        private java.util.Map<java.lang.String,​java.lang.String> localeIdToOrdinalRulesId
      • rulesIdToEquivalentULocale

        private java.util.Map<java.lang.String,​ULocale> rulesIdToEquivalentULocale
      • loader

        public static final PluralRulesLoader loader
        The only instance of the loader.
    • Constructor Detail

      • PluralRulesLoader

        private PluralRulesLoader()
        Access through singleton.
    • Method Detail

      • getFunctionalEquivalent

        public ULocale getFunctionalEquivalent​(ULocale locale,
                                               boolean[] isAvailable)
        Returns the functionally equivalent locale.
        Specified by:
        getFunctionalEquivalent in class PluralRules.Factory
        Parameters:
        locale - the locale to check
        isAvailable - if not null and of length > 0, this will hold 'true' at index 0 if locale is directly defined (without fallback) as having plural rules
        Returns:
        the functionally-equivalent locale
      • getLocaleIdToRulesIdMap

        private java.util.Map<java.lang.String,​java.lang.String> getLocaleIdToRulesIdMap​(PluralRules.PluralType type)
        Returns the lazily-constructed map.
      • getRulesIdToEquivalentULocaleMap

        private java.util.Map<java.lang.String,​ULocale> getRulesIdToEquivalentULocaleMap()
        Returns the lazily-constructed map.
      • checkBuildRulesIdMaps

        private void checkBuildRulesIdMaps()
        Lazily constructs the localeIdToRulesId and rulesIdToEquivalentULocale maps if necessary. These exactly reflect the contents of the locales resource in plurals.res.
      • getRulesIdForLocale

        public java.lang.String getRulesIdForLocale​(ULocale locale,
                                                    PluralRules.PluralType type)
        Gets the rulesId from the locale,with locale fallback. If there is no rulesId, return null. The rulesId might be the empty string if the rule is the default rule.
      • getOrCreateRulesForLocale

        public PluralRules getOrCreateRulesForLocale​(ULocale locale,
                                                     PluralRules.PluralType type)
        Gets the rule from the rulesId. If there is no rule for this rulesId, return null.
      • getPluralBundle

        public UResourceBundle getPluralBundle()
                                        throws java.util.MissingResourceException
        Return the plurals resource. Note MissingResourceException is unchecked, listed here for clarity. Callers should handle this exception.
        Throws:
        java.util.MissingResourceException
      • forLocale

        public PluralRules forLocale​(ULocale locale,
                                     PluralRules.PluralType type)
        Returns the plural rules for the the locale. If we don't have data, com.ibm.icu.text.PluralRules.DEFAULT is returned.
        Specified by:
        forLocale in class PluralRules.Factory
        Parameters:
        locale - The locale for which a PluralRules object is returned.
        type - The plural type (e.g., cardinal or ordinal).
        Returns:
        The predefined PluralRules object for this locale. If there's no predefined rules for this locale, the rules for the closest parent in the locale hierarchy that has one will be returned. The final fallback always returns the default rules.