本文整理汇总了Java中java.util.Locale.Builder类的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Builder类属于java.util.Locale包,在下文中一共展示了Builder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCurrentLocales
import java.util.Locale.Builder; //导入依赖的package包/类
/**
* Ensure that all current locale ids parse. Use DateFormat as a proxy
* for all current locale ids.
*/
public void testCurrentLocales() {
Locale[] locales = java.text.DateFormat.getAvailableLocales();
Builder builder = new Builder();
for (Locale target : locales) {
String tag = target.toLanguageTag();
// the tag recreates the original locale,
// except no_NO_NY
Locale tagResult = Locale.forLanguageTag(tag);
if (!target.getVariant().equals("NY")) {
assertEquals("tagResult", target, tagResult);
}
// the builder also recreates the original locale,
// except ja_JP_JP, th_TH_TH and no_NO_NY
Locale builderResult = builder.setLocale(target).build();
if (target.getVariant().length() != 2) {
assertEquals("builderResult", target, builderResult);
}
}
}
示例2: testGetExtension
import java.util.Locale.Builder; //导入依赖的package包/类
public void testGetExtension() {
// forLanguageTag does NOT normalize to hyphen
Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
assertEquals("some_ex-tension", null, locale.getExtension('a'));
// regular extension
locale = new Builder().setExtension('a', "some-ex-tension").build();
assertEquals("builder", "some-ex-tension", locale.getExtension('a'));
// returns null if extension is not present
assertEquals("empty b", null, locale.getExtension('b'));
// throws exception if extension tag is illegal
new ExpectIAE() { public void call() { Locale.forLanguageTag("").getExtension('\uD800'); }};
// 'x' is not an extension, it's a private use tag, but it's accessed through this API
locale = Locale.forLanguageTag("x-y-z-blork");
assertEquals("x", "y-z-blork", locale.getExtension('x'));
}
示例3: testBuilderSetLanguageTag
import java.util.Locale.Builder; //导入依赖的package包/类
public void testBuilderSetLanguageTag() {
String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
Builder builder = new Builder();
String result = builder
.setLanguageTag(source)
.build()
.toLanguageTag();
assertEquals("language", target, result);
// redundant extensions cause a failure
new BuilderILE() { public void call() { b.setLanguageTag("und-a-xx-yy-b-ww-A-00-11-c-vv"); }};
// redundant Unicode locale extension keys within an Unicode locale extension cause a failure
new BuilderILE() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
示例4: getLookupLocale
import java.util.Locale.Builder; //导入依赖的package包/类
/**
* Returns an instance of Locale used for service look up.
* The result Locale has no extensions except for ja_JP_JP
* and th_TH_TH
*
* @param locale the locale
* @return the locale used for service look up
*/
static Locale getLookupLocale(Locale locale) {
Locale lookupLocale = locale;
if (locale.hasExtensions()
&& !locale.equals(JRELocaleConstants.JA_JP_JP)
&& !locale.equals(JRELocaleConstants.TH_TH_TH)) {
// remove extensions
Builder locbld = new Builder();
try {
locbld.setLocale(locale);
locbld.clearExtensions();
lookupLocale = locbld.build();
} catch (IllformedLocaleException e) {
// A Locale with non-empty extensions
// should have well-formed fields except
// for ja_JP_JP and th_TH_TH. Therefore,
// it should never enter in this catch clause.
config(LocaleServiceProviderPool.class,
"A locale(" + locale + ") has non-empty extensions, but has illformed fields.");
// Fallback - script field will be lost.
lookupLocale = new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}
}
return lookupLocale;
}
示例5: get
import java.util.Locale.Builder; //导入依赖的package包/类
public static Set<Locale> get(String language, String country)
{
if(country == null)
return language(language);
Map<String, Set<Locale>> map = byLanguageCountry.get(language);
if(map == null) {
map = new HashMap<String, Set<Locale>>();
byLanguageCountry.put(language, map);
}
Set<Locale> locales = map.get(country);
if(locales != null)
return locales;
if(builder == null)
builder = new Locale.Builder();
synchronized(builder) {
builder.clear();
builder.setLanguage(language);
builder.setRegion(country);
put(builder.build());
}
return map.get(country);
}
示例6: asLangTag
import java.util.Locale.Builder; //导入依赖的package包/类
private static LangTag asLangTag(Locale.Builder locBuild) {
Locale lc = locBuild.build();
Set<Character> extkeys = lc.getExtensionKeys();
StringBuilder sb = new StringBuilder();
extkeys.forEach(k->{
String ext = lc.getExtension(k);
if ( sb.length() != 0 )
sb.append('-');
sb.append(k);
sb.append('-');
sb.append(ext);
});
String extension = sb.toString();
return new LangTag(lc.getLanguage(),
lc.getScript(),
lc.getCountry(),
lc.getVariant(),
extension);
}
示例7: getLookupLocale
import java.util.Locale.Builder; //导入依赖的package包/类
/**
* Returns an instance of Locale used for service look up.
* The result Locale has no extensions except for ja_JP_JP
* and th_TH_TH
*
* @param locale the locale
* @return the locale used for service look up
*/
private static Locale getLookupLocale(Locale locale) {
Locale lookupLocale = locale;
Set<Character> extensions = locale.getExtensionKeys();
if (!extensions.isEmpty()
&& !locale.equals(locale_ja_JP_JP)
&& !locale.equals(locale_th_TH_TH)) {
// remove extensions
Builder locbld = new Builder();
try {
locbld.setLocale(locale);
locbld.clearExtensions();
lookupLocale = locbld.build();
} catch (IllformedLocaleException e) {
// A Locale with non-empty extensions
// should have well-formed fields except
// for ja_JP_JP and th_TH_TH. Therefore,
// it should never enter in this catch clause.
config("A locale(" + locale + ") has non-empty extensions, but has illformed fields.");
// Fallback - script field will be lost.
lookupLocale = new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}
}
return lookupLocale;
}