本文整理汇总了Java中sun.util.locale.provider.LocaleProviderAdapter类的典型用法代码示例。如果您正苦于以下问题:Java LocaleProviderAdapter类的具体用法?Java LocaleProviderAdapter怎么用?Java LocaleProviderAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocaleProviderAdapter类属于sun.util.locale.provider包,在下文中一共展示了LocaleProviderAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstance
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
private static NumberFormat getInstance(LocaleProviderAdapter adapter,
Locale locale, int choice) {
NumberFormatProvider provider = adapter.getNumberFormatProvider();
NumberFormat numberFormat = null;
switch (choice) {
case NUMBERSTYLE:
numberFormat = provider.getNumberInstance(locale);
break;
case PERCENTSTYLE:
numberFormat = provider.getPercentInstance(locale);
break;
case CURRENCYSTYLE:
numberFormat = provider.getCurrencyInstance(locale);
break;
case INTEGERSTYLE:
numberFormat = provider.getIntegerInstance(locale);
break;
}
return numberFormat;
}
示例2: createBreakInstance
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) {
BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider();
BreakIterator iterator = null;
switch (type) {
case CHARACTER_INDEX:
iterator = breakIteratorProvider.getCharacterInstance(locale);
break;
case WORD_INDEX:
iterator = breakIteratorProvider.getWordInstance(locale);
break;
case LINE_INDEX:
iterator = breakIteratorProvider.getLineInstance(locale);
break;
case SENTENCE_INDEX:
iterator = breakIteratorProvider.getSentenceInstance(locale);
break;
}
return iterator;
}
示例3: get
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
/**
* Creates a DateFormat with the given time and/or date style in the given
* locale.
* @param timeStyle a value from 0 to 3 indicating the time format,
* ignored if flags is 2
* @param dateStyle a value from 0 to 3 indicating the time format,
* ignored if flags is 1
* @param flags either 1 for a time format, 2 for a date format,
* or 3 for a date/time format
* @param loc the locale for the format
*/
private static DateFormat get(int timeStyle, int dateStyle,
int flags, Locale loc) {
if ((flags & 1) != 0) {
if (timeStyle < 0 || timeStyle > 3) {
throw new IllegalArgumentException("Illegal time style " + timeStyle);
}
} else {
timeStyle = -1;
}
if ((flags & 2) != 0) {
if (dateStyle < 0 || dateStyle > 3) {
throw new IllegalArgumentException("Illegal date style " + dateStyle);
}
} else {
dateStyle = -1;
}
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc);
if (dateFormat == null) {
dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc);
}
return dateFormat;
}
示例4: getCandidateLocales
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
@Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
List<Locale> candidates = super.getCandidateLocales(baseName, locale);
// Weed out Locales which are known to have no resource bundles
int lastDot = baseName.lastIndexOf('.');
String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
if (!langtags.isEmpty()) {
for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
itr.remove();
}
}
}
// Force fallback to Locale.ENGLISH for CLDR time zone names support
if (locale.getLanguage() != "en"
&& type == CLDR && category.equals("TimeZoneNames")) {
candidates.add(candidates.size() - 1, Locale.ENGLISH);
}
return candidates;
}
示例5: adapterTest
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
static void adapterTest(String expected, String lang, String ctry) {
Locale testLocale = new Locale(lang, ctry);
LocaleProviderAdapter ldaExpected =
LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
return;
}
String preference = System.getProperty("java.locale.providers", "");
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
LocaleProviderAdapter.Type type = lda.getAdapterType();
System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
if (!type.toString().equals(expected)) {
throw new RuntimeException("Returned locale data adapter is not correct.");
}
}
示例6: bug8013903Test
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
static void bug8013903Test() {
if (System.getProperty("os.name").startsWith("Windows")) {
Date sampleDate = new Date(0x10000000000L);
String fallbackResult = "Heisei 16.Nov.03 (Wed) AM 11:53:47";
String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
Locale l = new Locale("ja", "JP", "JP");
SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
String result = sdf.format(sampleDate);
System.out.println(result);
if (LocaleProviderAdapter.getAdapterPreference()
.contains(LocaleProviderAdapter.Type.JRE)) {
if (!jreResult.equals(result)) {
throw new RuntimeException("Format failed. result: \"" +
result + "\", expected: \"" + jreResult);
}
} else {
// should be FALLBACK, as Windows HOST does not return
// display names
if (!fallbackResult.equals(result)) {
throw new RuntimeException("Format failed. result: \"" +
result + "\", expected: \"" + fallbackResult);
}
}
}
}
示例7: CLDRLocaleProviderAdapter
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
public CLDRLocaleProviderAdapter() {
LocaleDataMetaInfo nbmi = null;
try {
nbmi = AccessController.doPrivileged(new PrivilegedExceptionAction<LocaleDataMetaInfo>() {
@Override
public LocaleDataMetaInfo run() {
for (LocaleDataMetaInfo ldmi : ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) {
if (ldmi.getType() == LocaleProviderAdapter.Type.CLDR) {
return ldmi;
}
}
return null;
}
});
} catch (Exception e) {
// Catch any exception, and continue as if only CLDR's base locales exist.
}
nonBaseMetaInfo = nbmi;
}
示例8: main
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
public static void main(String... args) {
for (Locale locale : COMPAT_LOCALES) {
ResourceBundle compat
= LocaleProviderAdapter.forJRE()
.getLocaleResources(locale).getJavaTimeFormatData();
if (!compat.getLocale().equals(locale)) {
continue;
}
Locale cldrLocale = toCldrLocale(locale);
ResourceBundle cldr
= LocaleProviderAdapter.forType(Type.CLDR)
.getLocaleResources(locale).getJavaTimeFormatData();
if (!cldr.getLocale().equals(cldrLocale)) {
continue;
}
compareResources(compat, cldr);
}
if (errors > 0) {
throw new RuntimeException(errors + " failure(s)");
}
}
示例9: bug8013903Test
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
static void bug8013903Test() {
if (System.getProperty("os.name").startsWith("Windows")) {
Date sampleDate = new Date(0x10000000000L);
String hostResult = "\u5e73\u6210 16.11.03 (Wed) AM 11:53:47";
String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
Locale l = new Locale("ja", "JP", "JP");
SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
String result = sdf.format(sampleDate);
System.out.println(result);
if (LocaleProviderAdapter.getAdapterPreference()
.contains(LocaleProviderAdapter.Type.JRE)) {
if (!jreResult.equals(result)) {
throw new RuntimeException("Format failed. result: \"" +
result + "\", expected: \"" + jreResult);
}
} else {
// Windows display names. Subject to change if Windows changes its format.
if (!hostResult.equals(result)) {
throw new RuntimeException("Format failed. result: \"" +
result + "\", expected: \"" + hostResult);
}
}
}
}
示例10: getDisplayName
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
@Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
return rb.containsKey("field.week") ? rb.getString("field.week") : toString();
}
示例11: getDisplayName
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
@Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
if (rangeUnit == YEARS) { // only have values for week-of-year
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
return rb.containsKey("field.week") ? rb.getString("field.week") : name;
}
return name;
}
示例12: getLocalizedDateTimePattern
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
/**
* Gets the formatting pattern for date and time styles for a locale and chronology.
* The locale and chronology are used to lookup the locale specific format
* for the requested dateStyle and/or timeStyle.
*
* @param dateStyle the FormatStyle for the date
* @param timeStyle the FormatStyle for the time
* @param chrono the Chronology, non-null
* @param locale the locale, non-null
* @return the locale and Chronology specific formatting pattern
* @throws IllegalArgumentException if both dateStyle and timeStyle are null
*/
public static String getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
Chronology chrono, Locale locale) {
Objects.requireNonNull(locale, "locale");
Objects.requireNonNull(chrono, "chrono");
if (dateStyle == null && timeStyle == null) {
throw new IllegalArgumentException("Either dateStyle or timeStyle must be non-null");
}
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased().getLocaleResources(locale);
String pattern = lr.getJavaTimeDateTimePattern(
convertStyle(timeStyle), convertStyle(dateStyle), chrono.getCalendarType());
return pattern;
}
示例13: getProviderInstance
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
private static DateFormatSymbols getProviderInstance(Locale locale) {
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
DateFormatSymbols dfsyms = provider.getInstance(locale);
if (dfsyms == null) {
provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
dfsyms = provider.getInstance(locale);
}
return dfsyms;
}
示例14: getInstance
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
/**
* Gets the Collator for the desired locale.
* @param desiredLocale the desired locale.
* @return the Collator for the desired locale.
* @see java.util.Locale
* @see java.util.ResourceBundle
*/
public static Collator getInstance(Locale desiredLocale) {
SoftReference<Collator> ref = cache.get(desiredLocale);
Collator result = (ref != null) ? ref.get() : null;
if (result == null) {
LocaleProviderAdapter adapter;
adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class,
desiredLocale);
CollatorProvider provider = adapter.getCollatorProvider();
result = provider.getInstance(desiredLocale);
if (result == null) {
result = LocaleProviderAdapter.forJRE()
.getCollatorProvider().getInstance(desiredLocale);
}
while (true) {
if (ref != null) {
// Remove the empty SoftReference if any
cache.remove(desiredLocale, ref);
}
ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
if (ref == null) {
break;
}
Collator cachedColl = ref.get();
if (cachedColl != null) {
result = cachedColl;
break;
}
}
}
return (Collator) result.clone(); // make the world safe
}
示例15: getDisplayVariant
import sun.util.locale.provider.LocaleProviderAdapter; //导入依赖的package包/类
/**
* Returns a name for the locale's variant code that is appropriate for display to the
* user. If possible, the name will be localized for inLocale. If the locale
* doesn't specify a variant code, this function returns the empty string.
*
* @param inLocale The locale for which to retrieve the display variant code.
* @return The name of the display variant code appropriate to the given locale.
* @exception NullPointerException if <code>inLocale</code> is <code>null</code>
*/
public String getDisplayVariant(Locale inLocale) {
if (baseLocale.getVariant().length() == 0)
return "";
LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(inLocale);
String names[] = getDisplayVariantArray(inLocale);
// Get the localized patterns for formatting a list, and use
// them to format the list.
return formatList(names,
lr.getLocaleName("ListPattern"),
lr.getLocaleName("ListCompositionPattern"));
}