Class ICULocaleService.LocaleKey

  • Enclosing class:
    ICULocaleService

    public static class ICULocaleService.LocaleKey
    extends ICUService.Key
    A subclass of Key that implements a locale fallback mechanism. The first locale to search for is the locale provided by the client, and the fallback locale to search for is the current default locale. If a prefix is present, the currentDescriptor includes it before the locale proper, separated by "/". This is the default key instantiated by ICULocaleService.

    Canonicalization adjusts the locale string so that the section before the first understore is in lower case, and the rest is in upper case, with no trailing underscores.

    • Constructor Detail

      • LocaleKey

        protected LocaleKey​(String primaryID,
                            String canonicalPrimaryID,
                            String canonicalFallbackID,
                            int kind)
        PrimaryID is the user's requested locale string, canonicalPrimaryID is this string in canonical form, fallbackID is the current default locale's string in canonical form.
    • Method Detail

      • createWithCanonicalFallback

        public static ICULocaleService.LocaleKey createWithCanonicalFallback​(String primaryID,
                                                                             String canonicalFallbackID)
        Create a LocaleKey with canonical primary and fallback IDs.
      • createWithCanonicalFallback

        public static ICULocaleService.LocaleKey createWithCanonicalFallback​(String primaryID,
                                                                             String canonicalFallbackID,
                                                                             int kind)
        Create a LocaleKey with canonical primary and fallback IDs.
      • createWithCanonical

        public static ICULocaleService.LocaleKey createWithCanonical​(ULocale locale,
                                                                     String canonicalFallbackID,
                                                                     int kind)
        Create a LocaleKey with canonical primary and fallback IDs.
      • prefix

        public String prefix()
        Return the prefix associated with the kind, or null if the kind is KIND_ANY.
      • kind

        public int kind()
        Return the kind code associated with this key.
      • currentID

        public String currentID()
        Return the (canonical) current ID, or null if no current id.
        Overrides:
        currentID in class ICUService.Key
      • currentDescriptor

        public String currentDescriptor()
        Return the (canonical) current descriptor, or null if no current id. Includes the keywords, whereas the ID does not include keywords.
        Overrides:
        currentDescriptor in class ICUService.Key
      • canonicalLocale

        public ULocale canonicalLocale()
        Convenience method to return the locale corresponding to the (canonical) original ID.
      • currentLocale

        public ULocale currentLocale()
        Convenience method to return the ulocale corresponding to the (canonical) currentID.
      • fallback

        public boolean fallback()
        If the key has a fallback, modify the key and return true, otherwise return false.

        First falls back through the primary ID, then through the fallbackID. The final fallback is "" (root) unless the primary id was "" (root), in which case there is no fallback.

        Overrides:
        fallback in class ICUService.Key
      • isFallbackOf

        public boolean isFallbackOf​(String id)
        If a key created from id would eventually fallback to match the canonical ID of this key, return true.
        Overrides:
        isFallbackOf in class ICUService.Key