Class LocaleMatcher.Builder
- java.lang.Object
-
- com.ibm.icu.util.LocaleMatcher.Builder
-
- Enclosing class:
- LocaleMatcher
public static final class LocaleMatcher.Builder extends java.lang.Object
LocaleMatcher Builder.- See Also:
LocaleMatcher.builder()
-
-
Field Summary
Fields Modifier and Type Field Description private ULocale
defaultLocale
private LocaleMatcher.Demotion
demotion
private LocaleMatcher.Direction
direction
private LocaleMatcher.FavorSubtag
favor
private ULocale
maxDistanceDesired
private ULocale
maxDistanceSupported
private java.util.List<ULocale>
supportedLocales
private int
thresholdDistance
private boolean
withDefault
-
Constructor Summary
Constructors Modifier Constructor Description private
Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description LocaleMatcher.Builder
addSupportedLocale(java.util.Locale locale)
Adds another supported locale.LocaleMatcher.Builder
addSupportedULocale(ULocale locale)
Adds another supported locale.LocaleMatcher
build()
Builds and returns a new locale matcher.LocaleMatcher.Builder
internalSetThresholdDistance(int thresholdDistance)
Deprecated.This API is ICU internal only.LocaleMatcher.Builder
setDefaultLocale(java.util.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.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.LocaleMatcher.Builder
setDemotionPerDesiredLocale(LocaleMatcher.Demotion demotion)
Option for whether all desired locales are treated equally or earlier ones are preferred (this is the default).LocaleMatcher.Builder
setDirection(LocaleMatcher.Direction direction)
Option for whether to include or ignore one-way (fallback) match data.LocaleMatcher.Builder
setFavorSubtag(LocaleMatcher.FavorSubtag subtag)
If SCRIPT, then the language differences are smaller than script differences.LocaleMatcher.Builder
setMaxDistance(ULocale desired, ULocale supported)
Sets the maximum distance for an acceptable match.LocaleMatcher.Builder
setMaxDistance(java.util.Locale desired, java.util.Locale supported)
Sets the maximum distance for an acceptable match.LocaleMatcher.Builder
setNoDefaultLocale()
Sets no default locale.LocaleMatcher.Builder
setSupportedLocales(java.lang.String locales)
Parses the string likeLocalePriorityList
does and sets the supported locales accordingly.LocaleMatcher.Builder
setSupportedLocales(java.util.Collection<java.util.Locale> locales)
Copies the supported locales, preserving iteration order.LocaleMatcher.Builder
setSupportedULocales(java.util.Collection<ULocale> locales)
Copies the supported locales, preserving iteration order.java.lang.String
toString()
-
-
-
Field Detail
-
supportedLocales
private java.util.List<ULocale> supportedLocales
-
thresholdDistance
private int thresholdDistance
-
demotion
private LocaleMatcher.Demotion demotion
-
defaultLocale
private ULocale defaultLocale
-
withDefault
private boolean withDefault
-
favor
private LocaleMatcher.FavorSubtag favor
-
direction
private LocaleMatcher.Direction direction
-
maxDistanceDesired
private ULocale maxDistanceDesired
-
maxDistanceSupported
private ULocale maxDistanceSupported
-
-
Method Detail
-
setSupportedLocales
public LocaleMatcher.Builder setSupportedLocales(java.lang.String locales)
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
public LocaleMatcher.Builder setSupportedULocales(java.util.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(java.util.Collection<java.util.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(java.util.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) ifsetNoDefaultLocale()
is called.- Parameters:
defaultLocale
- the default locale- Returns:
- this Builder object
-
setDefaultLocale
public LocaleMatcher.Builder setDefaultLocale(java.util.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) ifsetNoDefaultLocale()
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(java.util.Locale desired, java.util.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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-