Class LocaleMatcher.Builder

java.lang.Object
com.ibm.icu.util.LocaleMatcher.Builder
Enclosing class:
LocaleMatcher

public static final class LocaleMatcher.Builder extends Object
LocaleMatcher Builder.
See Also:
  • Method Details

    • setSupportedLocales

      public LocaleMatcher.Builder setSupportedLocales(String locales)
      Parses the string like LocalePriorityList does and sets the supported locales accordingly. Clears any previously set/added supported locales first.
      Parameters:
      locales - the string of locales to set, to be parsed like LocalePriorityList does
      Returns:
      this Builder object
    • setSupportedULocales

      public LocaleMatcher.Builder setSupportedULocales(Collection<ULocale> locales)
      Copies the supported locales, preserving iteration order. Clears any previously set/added supported locales first. Duplicates are allowed, and are not removed.
      Parameters:
      locales - the list of locales
      Returns:
      this Builder object
    • setSupportedLocales

      public LocaleMatcher.Builder setSupportedLocales(Collection<Locale> locales)
      Copies the supported locales, preserving iteration order. Clears any previously set/added supported locales first. Duplicates are allowed, and are not removed.
      Parameters:
      locales - the list of locale
      Returns:
      this Builder object
    • addSupportedULocale

      public LocaleMatcher.Builder addSupportedULocale(ULocale locale)
      Adds another supported locale. Duplicates are allowed, and are not removed.
      Parameters:
      locale - another locale
      Returns:
      this Builder object
    • addSupportedLocale

      public LocaleMatcher.Builder addSupportedLocale(Locale locale)
      Adds another supported locale. Duplicates are allowed, and are not removed.
      Parameters:
      locale - another locale
      Returns:
      this Builder object
    • setNoDefaultLocale

      public LocaleMatcher.Builder setNoDefaultLocale()
      Sets no default locale. There will be no explicit or implicit default locale. If there is no good match, then the matcher will return null for the best supported locale.
    • setDefaultULocale

      public LocaleMatcher.Builder setDefaultULocale(ULocale defaultLocale)
      Sets the default locale; if null, or if it is not set explicitly, then the first supported locale is used as the default locale. There is no default locale at all (null will be returned instead) if setNoDefaultLocale() is called.
      Parameters:
      defaultLocale - the default locale
      Returns:
      this Builder object
    • setDefaultLocale

      public LocaleMatcher.Builder setDefaultLocale(Locale defaultLocale)
      Sets the default locale; if null, or if it is not set explicitly, then the first supported locale is used as the default locale. There is no default locale at all (null will be returned instead) if setNoDefaultLocale() is called.
      Parameters:
      defaultLocale - the default locale
      Returns:
      this Builder object
    • setFavorSubtag

      public LocaleMatcher.Builder setFavorSubtag(LocaleMatcher.FavorSubtag subtag)
      If SCRIPT, then the language differences are smaller than script differences. This is used in situations (such as maps) where it is better to fall back to the same script than a similar language.
      Parameters:
      subtag - the subtag to favor
      Returns:
      this Builder object
    • setDemotionPerDesiredLocale

      public LocaleMatcher.Builder setDemotionPerDesiredLocale(LocaleMatcher.Demotion demotion)
      Option for whether all desired locales are treated equally or earlier ones are preferred (this is the default).
      Parameters:
      demotion - the demotion per desired locale to set.
      Returns:
      this Builder object
    • setDirection

      public LocaleMatcher.Builder setDirection(LocaleMatcher.Direction direction)
      Option for whether to include or ignore one-way (fallback) match data. By default, they are included.
      Parameters:
      direction - the match direction to set.
      Returns:
      this Builder object
    • setMaxDistance

      public LocaleMatcher.Builder setMaxDistance(Locale desired, Locale supported)
      Sets the maximum distance for an acceptable match. The matcher will return a match for a pair of locales only if they match at least as well as the pair given here.

      For example, setMaxDistance(en-US, en-GB) limits matches to ones where the (desired, support) locales have a distance no greater than a region subtag difference. This is much stricter than the CLDR default.

      The details of locale matching are subject to changes in CLDR data and in the algorithm. Specifying a maximum distance in relative terms via a sample pair of locales insulates from changes that affect all distance metrics similarly, but some changes will necessarily affect relative distances between different pairs of locales.

      Parameters:
      desired - the desired locale for distance comparison.
      supported - the supported locale for distance comparison.
      Returns:
      this Builder object
    • setMaxDistance

      public LocaleMatcher.Builder setMaxDistance(ULocale desired, ULocale supported)
      Sets the maximum distance for an acceptable match. The matcher will return a match for a pair of locales only if they match at least as well as the pair given here.

      For example, setMaxDistance(en-US, en-GB) limits matches to ones where the (desired, support) locales have a distance no greater than a region subtag difference. This is much stricter than the CLDR default.

      The details of locale matching are subject to changes in CLDR data and in the algorithm. Specifying a maximum distance in relative terms via a sample pair of locales insulates from changes that affect all distance metrics similarly, but some changes will necessarily affect relative distances between different pairs of locales.

      Parameters:
      desired - the desired locale for distance comparison.
      supported - the supported locale for distance comparison.
      Returns:
      this Builder object
    • internalSetThresholdDistance

      @Deprecated public LocaleMatcher.Builder internalSetThresholdDistance(int thresholdDistance)
      Deprecated.
      This API is ICU internal only.
      Internal only!
      Parameters:
      thresholdDistance - the thresholdDistance to set, with -1 = default
      Returns:
      this Builder object
    • build

      public LocaleMatcher build()
      Builds and returns a new locale matcher. This builder can continue to be used.
      Returns:
      new LocaleMatcher.
    • toString

      public String toString()
      Overrides:
      toString in class Object