Locale_Builder

extern class java.util.Locale_Builderimport java.util.LocaleAvailable in java
Builder
is used to build instances of
Locale
from values configured by the setters. Unlike the
Locale
constructors, the
Builder
checks if a value configured by a setter satisfies the syntax requirements defined by the
Locale
class. A
Locale
object created by a
Builder
is well-formed and can be transformed to a well-formed IETF BCP 47 language tag without losing information.
<p><b>Note:</b> The
Locale
class does not provide any syntactic restrictions on variant, while BCP 47 requires each variant subtag to be 5 to 8 alphanumerics or a single numeric followed by 3 alphanumerics. The method
setVariant
throws
IllformedLocaleException
for a variant that does not satisfy this restriction. If it is necessary to support such a variant, use a Locale constructor. However, keep in mind that a
Locale
object created this way might lose the variant information when transformed to a BCP 47 language tag.
<p>The following example shows how to create a
Locale
object with the
Builder
. <blockquote> <pre> Locale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build(); </pre> </blockquote>
<p>Builders can be reused;
clear()
resets all fields to their default values.
@see Locale#forLanguageTag @since 1.7
function new() : VoidConstructs an empty Builder. The default value of all fields, extensions, and private use information is the empty string. function addUnicodeLocaleAttribute( param1 : String ) : Locale_BuilderAdds a unicode locale attribute, if not already present, otherwise has no effect. The attribute must not be null and must be <a href="./Locale.html#def_locale_extension">well-formed</a> or an exception is thrown.
param attribute the attribute return This builder. @throws NullPointerException if
attribute
is null @throws IllformedLocaleException if
attribute
is ill-formed @see #setExtension(char, String)
function build() : LocaleReturns an instance of
Locale
created from the fields set on this builder.
<p>This applies the conversions listed in {@link Locale#forLanguageTag} when constructing a Locale. (Grandfathered tags are handled in {@link #setLanguageTag}.)
@return A Locale.
function clear() : Locale_BuilderResets the builder to its initial, empty state.
@return This builder.
function clearExtensions() : Locale_BuilderResets the extensions to their initial, empty state. Language, script, region and variant are unchanged.
return This builder. see #setExtension(char, String)
function removeUnicodeLocaleAttribute( param1 : String ) : Locale_BuilderRemoves a unicode locale attribute, if present, otherwise has no effect. The attribute must not be null and must be <a href="./Locale.html#def_locale_extension">well-formed</a> or an exception is thrown.
<p>Attribute comparision for removal is case-insensitive.
param attribute the attribute return This builder. @throws NullPointerException if
attribute
is null @throws IllformedLocaleException if
attribute
is ill-formed @see #setExtension(char, String)
function setExtension( param1 : Char16, param2 : String ) : Locale_BuilderSets the extension for the given key. If the value is null or the empty string, the extension is removed. Otherwise, the extension must be <a href="./Locale.html#def_extensions">well-formed</a> or an exception is thrown.
<p><b>Note:</b> The key {@link Locale#UNICODE_LOCALE_EXTENSION 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.
<p><b>Note:</b> The key {@link Locale#PRIVATE_USE_EXTENSION PRIVATE_USE_EXTENSION} ('x') is used for the private use code. To be well-formed, the value for this key needs only to have subtags of one to eight alphanumeric characters, not two to eight as in the general case.
param key the extension key param value the extension value return This builder. throws IllformedLocaleException if
key
is illegal or
value
is ill-formed @see #setUnicodeLocaleKeyword(String, String)
function setLanguage( param1 : String ) : Locale_BuilderSets the language. If
language
is the empty string or null, the language in this
Builder
is removed. Otherwise, the language must be <a href="./Locale.html#def_language">well-formed</a> or an exception is thrown.
<p>The typical language value is a two or three-letter language code as defined in ISO639.
param language the language return This builder. @throws IllformedLocaleException if
language
is ill-formed
function setLanguageTag( param1 : String ) : Locale_BuilderResets the Builder to match the provided IETF BCP 47 language tag. Discards the existing state. Null and the empty string cause the builder to be reset, like {@link #clear}. Grandfathered tags (see {@link Locale#forLanguageTag}) are converted to their canonical form before being processed. Otherwise, the language tag must be well-formed (see {@link Locale}) or an exception is thrown (unlike
Locale.forLanguageTag
, which just discards ill-formed and following portions of the tag).
param languageTag the language tag return This builder. @throws IllformedLocaleException if
languageTag
is ill-formed @see Locale#forLanguageTag(String)
function setLocale( param1 : Locale ) : Locale_BuilderResets the
Builder
to match the provided
locale
. Existing state is discarded.
<p>All fields of the locale must be well-formed, see {@link Locale}.
<p>Locales with any ill-formed fields cause
IllformedLocaleException
to be thrown, except for the following three cases which are accepted for compatibility reasons:<ul> <li>Locale("ja", "JP", "JP") is treated as "ja-JP-u-ca-japanese" <li>Locale("th", "TH", "TH") is treated as "th-TH-u-nu-thai" <li>Locale("no", "NO", "NY") is treated as "nn-NO"</ul>
param locale the locale return This builder. @throws IllformedLocaleException if
locale
has any ill-formed fields. @throws NullPointerException if
locale
is null.
function setRegion( param1 : String ) : Locale_BuilderSets the region. If region is null or the empty string, the region in this
Builder
is removed. Otherwise, the region must be <a href="./Locale.html#def_region">well-formed</a> or an exception is thrown.
<p>The typical region value is a two-letter ISO 3166 code or a three-digit UN M.49 area code.
<p>The country value in the
Locale
created by the
Builder
is always normalized to upper case.
param region the region return This builder. @throws IllformedLocaleException if
region
is ill-formed
function setScript( param1 : String ) : Locale_BuilderSets the script. If
script
is null or the empty string, the script in this
Builder
is removed. Otherwise, the script must be <a href="./Locale.html#def_script">well-formed</a> or an exception is thrown.
<p>The typical script value is a four-letter script code as defined by ISO 15924.
param script the script return This builder. @throws IllformedLocaleException if
script
is ill-formed
function setUnicodeLocaleKeyword( param1 : String, param2 : String ) : Locale_BuilderSets the Unicode locale keyword type for the given key. If the type is null, the Unicode keyword is removed. Otherwise, the key must be non-null and both key and type must be <a href="./Locale.html#def_locale_extension">well-formed</a> or an exception is thrown.
<p>Keys and types are converted to lower case.
<p><b>Note</b>:Setting the 'u' extension via {@link #setExtension} replaces all Unicode locale keywords with those defined in the extension.
param key the Unicode locale key param type the Unicode locale type return This builder. throws IllformedLocaleException if
key
or
type
is ill-formed @throws NullPointerException if
key
is null @see #setExtension(char, String)
function setVariant( param1 : String ) : Locale_BuilderSets the variant. If variant is null or the empty string, the variant in this
Builder
is removed. Otherwise, it must consist of one or more <a href="./Locale.html#def_variant">well-formed</a> subtags, or an exception is thrown.
<p><b>Note:</b> This method checks if
variant
satisfies the IETF BCP 47 variant subtag's syntax requirements, and normalizes the value to lowercase letters. However, the
Locale
class does not impose any syntactic restriction on variant, and the variant value in
Locale
is case sensitive. To set such a variant, use a Locale constructor.
param variant the variant return This builder. @throws IllformedLocaleException if
variant
is ill-formed
version #19107, modified 2013-05-08 10:59:25 by api
0 comment