Class LocaleMatcher.Builder
- Enclosing class:
LocaleMatcher
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddSupportedLocale
(Locale locale) Adds another supported locale.addSupportedULocale
(ULocale locale) Adds another supported locale.build()
Builds and returns a new locale matcher.internalSetThresholdDistance
(int thresholdDistance) Deprecated.This API is ICU internal only.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.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.Option for whether all desired locales are treated equally or earlier ones are preferred (this is the default).setDirection
(LocaleMatcher.Direction direction) Option for whether to include or ignore one-way (fallback) match data.If SCRIPT, then the language differences are smaller than script differences.setMaxDistance
(ULocale desired, ULocale supported) Sets the maximum distance for an acceptable match.setMaxDistance
(Locale desired, Locale supported) Sets the maximum distance for an acceptable match.Sets no default locale.setSupportedLocales
(String locales) Parses the string likeLocalePriorityList
does and sets the supported locales accordingly.setSupportedLocales
(Collection<Locale> locales) Copies the supported locales, preserving iteration order.setSupportedULocales
(Collection<ULocale> locales) Copies the supported locales, preserving iteration order.toString()
-
Method Details
-
setSupportedLocales
Parses the string likeLocalePriorityList
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
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
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
Adds another supported locale. Duplicates are allowed, and are not removed.- Parameters:
locale
- another locale- Returns:
- this Builder object
-
addSupportedLocale
Adds another supported locale. Duplicates are allowed, and are not removed.- Parameters:
locale
- another locale- Returns:
- this Builder object
-
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
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) ifsetNoDefaultLocale()
is called.- Parameters:
defaultLocale
- the default locale- Returns:
- this Builder object
-
setDefaultLocale
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) ifsetNoDefaultLocale()
is called.- Parameters:
defaultLocale
- the default locale- Returns:
- this Builder object
-
setFavorSubtag
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
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
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
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
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.This API is ICU internal only.Internal only!- Parameters:
thresholdDistance
- the thresholdDistance to set, with -1 = default- Returns:
- this Builder object
-
build
Builds and returns a new locale matcher. This builder can continue to be used.- Returns:
- new LocaleMatcher.
-
toString
-