|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.ibm.icu.util.ULocale.Builder
public static final class ULocale.Builder
Builder is used to build instances of ULocale
from values configured by the setter. Unlike the ULocale
constructors, the Builder checks if a value configured by a
setter satisfies the syntactical requirements defined by the ULocale
class. A ULocale object created by a Builder is
well-formed and can be transformed to a well-formed IETF BCP 47 language tag
without losing information.
Note: The ULocale class does not provide
any syntactical restrictions on variant, while BCP 47
requires each variant subtag to be 5 to 8 alphanumeric letters or a single
numeric letter followed by 3 alphanumeric letters. By default,
the setVariant method throws IllformedLocaleException
for a variant that does not satisfy the syntax above. If it is
necessary to support such a variant, you could use the constructor
Builder(boolean isLenientVariant) passing true to
skip the syntax validation for variant. However, you should keep in
mind that a Locale object created this way might lose
the variant information when transformed to a BCP 47 language tag.
The following example shows how to create a ULocale object
with the Builder.
ULocale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build();
Builders can be reused; clear() resets all
fields to their default values.
ULocale.toLanguageTag()| Constructor Summary | |
|---|---|
ULocale.Builder()
Constructs an empty Builder. |
|
ULocale.Builder(boolean isLenientVariant)
Constructs an empty Builder with an option whether to allow setVariant to accept a value that does not
conform to the IETF BCP 47 variant subtag's syntax requirements. |
|
| Method Summary | |
|---|---|
ULocale |
build()
Returns an instance of Locale created from the fields set on this builder. |
ULocale.Builder |
clear()
Resets the builder to its initial, empty state. |
ULocale.Builder |
clearExtensions()
Resets the extensions to their initial, empty state. |
boolean |
isLenientVariant()
Returns true if this Builder accepts a value that does
not conform to the IETF BCP 47 variant subtag's syntax requirements
in setVariant |
ULocale.Builder |
setExtension(char key,
String value)
Sets the extension for the given key. |
ULocale.Builder |
setLanguage(String language)
Sets the language. |
ULocale.Builder |
setLanguageTag(String languageTag)
Resets the builder to match the provided IETF BCP 47 language tag. |
ULocale.Builder |
setLocale(ULocale locale)
Resets the Builder to match the provided locale. |
ULocale.Builder |
setRegion(String region)
Sets the region. |
ULocale.Builder |
setScript(String script)
Sets the script. |
ULocale.Builder |
setUnicodeLocaleKeyword(String key,
String type)
Sets the Unicode locale keyword type for the given key. |
ULocale.Builder |
setVariant(String variant)
Sets the variant. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ULocale.Builder()
public ULocale.Builder(boolean isLenientVariant)
setVariant to accept a value that does not
conform to the IETF BCP 47 variant subtag's syntax requirements.
isLenientVariant - When true, this Builder
will accept an ill-formed variant.setVariant(String)| Method Detail |
|---|
public boolean isLenientVariant()
Builder accepts a value that does
not conform to the IETF BCP 47 variant subtag's syntax requirements
in setVariant
Build accepts an ill-formed variant.public ULocale.Builder setLocale(ULocale locale)
Builder to match the provided locale.
The previous state of the builder is discarded. Fields that do
not conform to the ULocale class specification, for example,
a single letter language, are ill-formed.
locale - the locale
IllformedLocaleException - if locale has
any ill-formed fields.public ULocale.Builder setLanguageTag(String languageTag)
languageTag - the language tag
IllformedLocaleException - if languageTag is ill-formed.
NullPointerException - if languageTag is null.ULocale.forLanguageTag(String)public ULocale.Builder setLanguage(String language)
language is the empty string,
the language in this Builder will be removed.
Typical language value is a two or three-letter language
code as defined in ISO639.
Well-formed values are any string of two to eight alpha
letters. This method accepts upper case alpha letters
[A-Z], but the language value in the ULocale
created by the Builder is always normalized
to lower case letters.
language - the language
IllformedLocaleException - if language is ill-formedpublic ULocale.Builder setScript(String script)
script is the empty string,
the script in this Builder is removed.
Typical script value is a four-letter script code as defined by ISO 15924.
Well-formed values are any string of four alpha letters.
This method accepts both upper and lower case alpha letters [a-zA-Z],
but the script value in the ULocale created by the
Builder is always normalized to title case
(the first letter is upper case and the rest of letters are lower case).
script - the script
IllformedLocaleException - if script is ill-formedpublic ULocale.Builder setRegion(String region)
Builder is removed.
Typical region value is a two-letter ISO 3166 code or a three-digit UN M.49
area code. Well-formed values are any two-letter or three-digit string.
This method accepts lower case letters [a-z], but the country value in
the ULocale created by the Builder is always
normalized to upper case.
region - the region
IllformedLocaleException - if region is ill-formedpublic ULocale.Builder setVariant(String variant)
Builder is removed.
Note: By default, this method checks if variant
satisfies the IETF BCP 47 variant subtag's syntax requirements.
However, the ULocale class itself does not impose any syntactical
restriction on variant. When a Builder is created by the
constructor Builder(boolean isLenientVariant)
with true, this method skips the syntax check.
variant - the variant
IllformedLocaleException - if variant is ill-formed
public ULocale.Builder setExtension(char key,
String value)
[0-9A-Za-z]. Keys
are case-insensitive, so for example 'z' and 'Z' represent
the same extension. In general, well-formed values are any
series of fields of two to eight alphanumeric characters,
separated by hyphen or underscore.
Note: The key UNICODE_LOCALE_EXTENSION ('u') is used for the Unicode locale extension.
Setting a value for this key replaces any existing Unicode locale key/type
pairs with those defined in the extension.
To be well-formed, a value for this extension must meet the additional
constraints that each locale key is two alphanumeric characters,
followed by at least one locale type subtag represented by
three to eight alphanumeric characters, and that the keys and types
be legal Unicode locale keys and values.
Note: The key PRIVATE_USE_EXTENSION ('x') is used for the private use code. To be
well-formed, the value for this key needs only to have fields of one to
eight alphanumeric characters, not two to eight as in the general case.
key - the extension keyvalue - the extension value
IllformedLocaleException - if key is illegal
or value is ill-formedsetUnicodeLocaleKeyword(String, String)
public ULocale.Builder setUnicodeLocaleKeyword(String key,
String type)
Note:Setting the 'u' extension replaces all Unicode locale keywords with those defined in the extension.
key - the Unicode locale keytype - the Unicode locale type
IllformedLocaleException - if key or type
is ill-formedsetExtension(char, String)public ULocale.Builder clear()
public ULocale.Builder clearExtensions()
setExtension(char, String)public ULocale build()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||