本文整理汇总了Java中sun.util.locale.provider.LocaleProviderAdapter.getAdapter方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleProviderAdapter.getAdapter方法的具体用法?Java LocaleProviderAdapter.getAdapter怎么用?Java LocaleProviderAdapter.getAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.util.locale.provider.LocaleProviderAdapter
的用法示例。
在下文中一共展示了LocaleProviderAdapter.getAdapter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: createBreakInstance
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
private static BreakIterator createBreakInstance(Locale locale,
int type) {
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(BreakIteratorProvider.class, locale);
BreakIterator iterator = createBreakInstance(adapter, locale, type);
if (iterator == null) {
iterator = createBreakInstance(LocaleProviderAdapter.forJRE(), locale, type);
}
return iterator;
}
示例3: 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;
}
示例4: getDefaultPattern
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
private static String getDefaultPattern(Locale loc) {
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
LocaleResources lr = adapter.getLocaleResources(loc);
if (lr == null) {
lr = LocaleProviderAdapter.forJRE().getLocaleResources(loc);
}
return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null);
}
示例5: bug7198834Test
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
static void bug7198834Test() {
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
LocaleProviderAdapter.Type type = lda.getAdapterType();
if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
String date = df.format(new Date());
if (date.charAt(date.length()-1) == ' ') {
throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
}
} else {
System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
}
}
示例6: getDefaultPattern
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
private static String getDefaultPattern(Locale locale) {
// Get the pattern for the default locale.
LocaleProviderAdapter adapter;
adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
locale);
LocaleResources lr = adapter.getLocaleResources(locale);
if (lr == null) {
lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
}
String[] all = lr.getNumberPatterns();
return all[0];
}
示例7: 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
}
示例8: initialize
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
/**
* Initializes the symbols from the FormatData resource bundle.
*/
private void initialize( Locale locale ) {
this.locale = locale;
// get resource bundle data
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
// Avoid potential recursions
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
Object[] data = adapter.getLocaleResources(locale).getDecimalFormatSymbolsData();
String[] numberElements = (String[]) data[0];
decimalSeparator = numberElements[0].charAt(0);
groupingSeparator = numberElements[1].charAt(0);
patternSeparator = numberElements[2].charAt(0);
percent = numberElements[3].charAt(0);
zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
digit = numberElements[5].charAt(0);
minusSign = numberElements[6].charAt(0);
exponential = numberElements[7].charAt(0);
exponentialSeparator = numberElements[7]; //string representation new since 1.6
perMill = numberElements[8].charAt(0);
infinity = numberElements[9];
NaN = numberElements[10];
// maybe filled with previously cached values, or null.
intlCurrencySymbol = (String) data[1];
currencySymbol = (String) data[2];
// Currently the monetary decimal separator is the same as the
// standard decimal separator for all locales that we support.
// If that changes, add a new entry to NumberElements.
monetarySeparator = decimalSeparator;
}
示例9: initializeData
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
private void initializeData(Locale desiredLocale) {
locale = desiredLocale;
// Copy values of a cached instance if any.
SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
DateFormatSymbols dfs;
if (ref != null && (dfs = ref.get()) != null) {
copyMembers(dfs, this);
return;
}
// Initialize the fields from the ResourceBundle for locale.
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
// Avoid any potential recursions
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);
// JRE and CLDR use different keys
// JRE: Eras, short.Eras and narrow.Eras
// CLDR: long.Eras, Eras and narrow.Eras
if (resource.containsKey("Eras")) {
eras = resource.getStringArray("Eras");
} else if (resource.containsKey("long.Eras")) {
eras = resource.getStringArray("long.Eras");
} else if (resource.containsKey("short.Eras")) {
eras = resource.getStringArray("short.Eras");
}
months = resource.getStringArray("MonthNames");
shortMonths = resource.getStringArray("MonthAbbreviations");
ampms = resource.getStringArray("AmPmMarkers");
localPatternChars = resource.getString("DateTimePatternChars");
// Day of week names are stored in a 1-based array.
weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
// Put a clone in the cache
ref = new SoftReference<>((DateFormatSymbols)this.clone());
SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
if (x != null) {
DateFormatSymbols y = x.get();
if (y == null) {
// Replace the empty SoftReference with ref.
cachedInstances.put(locale, ref);
}
}
}
示例10: bug8010666Test
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
static void bug8010666Test() {
if (System.getProperty("os.name").startsWith("Windows")) {
NumberFormat nf = NumberFormat.getInstance(Locale.US);
try {
double ver = nf.parse(System.getProperty("os.version"))
.doubleValue();
System.out.printf("Windows version: %.1f\n", ver);
if (ver >= 6.0) {
LocaleProviderAdapter lda =
LocaleProviderAdapter.getAdapter(
LocaleNameProvider.class, Locale.ENGLISH);
LocaleProviderAdapter.Type type = lda.getAdapterType();
if (type == LocaleProviderAdapter.Type.HOST) {
LocaleNameProvider lnp = lda.getLocaleNameProvider();
Locale mkmk = Locale.forLanguageTag("mk-MK");
String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
String hostResult =
lnp.getDisplayLanguage(mkmk.getLanguage(),
Locale.ENGLISH);
System.out.printf(" Display language name for" +
" (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
hostResult, result);
if (result == null ||
hostResult != null &&
!result.equals(hostResult)) {
throw new RuntimeException("Display language name" +
" mismatch for \"mk\". Returned name was" +
" \"" + result + "\", result(HOST): \"" +
hostResult + "\"");
}
result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
hostResult =
lnp.getDisplayLanguage(Locale.US.getLanguage(),
Locale.ENGLISH);
System.out.printf(" Display language name for" +
" (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
hostResult, result);
if (result == null ||
hostResult != null &&
!result.equals(hostResult)) {
throw new RuntimeException("Display language name" +
" mismatch for \"en\". Returned name was" +
" \"" + result + "\", result(HOST): \"" +
hostResult + "\"");
}
if (ver >= 6.1) {
result = Locale.US.getDisplayCountry(Locale.ENGLISH);
hostResult = lnp.getDisplayCountry(
Locale.US.getCountry(), Locale.ENGLISH);
System.out.printf(" Display country name for" +
" (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
hostResult, result);
if (result == null ||
hostResult != null &&
!result.equals(hostResult)) {
throw new RuntimeException("Display country name" +
" mismatch for \"US\". Returned name was" +
" \"" + result + "\", result(HOST): \"" +
hostResult + "\"");
}
}
} else {
throw new RuntimeException("Windows Host" +
" LocaleProviderAdapter was not selected for" +
" English locale.");
}
}
} catch (ParseException pe) {
throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
}
}
}
示例11: initializeData
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
/**
* Initializes this DateFormatSymbols with the locale data. This method uses
* a cached DateFormatSymbols instance for the given locale if available. If
* there's no cached one, this method creates an uninitialized instance and
* populates its fields from the resource bundle for the locale, and caches
* the instance. Note: zoneStrings isn't initialized in this method.
*/
private void initializeData(Locale locale) {
SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
DateFormatSymbols dfs;
if (ref == null || (dfs = ref.get()) == null) {
if (ref != null) {
// Remove the empty SoftReference
cachedInstances.remove(locale, ref);
}
dfs = new DateFormatSymbols(false);
// Initialize the fields from the ResourceBundle for locale.
LocaleProviderAdapter adapter
= LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
// Avoid any potential recursions
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
ResourceBundle resource
= ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);
dfs.locale = locale;
// JRE and CLDR use different keys
// JRE: Eras, short.Eras and narrow.Eras
// CLDR: long.Eras, Eras and narrow.Eras
if (resource.containsKey("Eras")) {
dfs.eras = resource.getStringArray("Eras");
} else if (resource.containsKey("long.Eras")) {
dfs.eras = resource.getStringArray("long.Eras");
} else if (resource.containsKey("short.Eras")) {
dfs.eras = resource.getStringArray("short.Eras");
}
dfs.months = resource.getStringArray("MonthNames");
dfs.shortMonths = resource.getStringArray("MonthAbbreviations");
dfs.ampms = resource.getStringArray("AmPmMarkers");
dfs.localPatternChars = resource.getString("DateTimePatternChars");
// Day of week names are stored in a 1-based array.
dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
// Put dfs in the cache
ref = new SoftReference<>(dfs);
SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
if (x != null) {
DateFormatSymbols y = x.get();
if (y == null) {
// Replace the empty SoftReference with ref.
cachedInstances.replace(locale, x, ref);
} else {
ref = x;
dfs = y;
}
}
// If the bundle's locale isn't the target locale, put another cache
// entry for the bundle's locale.
Locale bundleLocale = resource.getLocale();
if (!bundleLocale.equals(locale)) {
SoftReference<DateFormatSymbols> z
= cachedInstances.putIfAbsent(bundleLocale, ref);
if (z != null && z.get() == null) {
cachedInstances.replace(bundleLocale, z, ref);
}
}
}
// Copy the field values from dfs to this instance.
copyMembers(dfs, this);
}
示例12: DecimalFormat
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
/**
* Creates a DecimalFormat using the default pattern and symbols
* for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
* This is a convenient way to obtain a
* DecimalFormat when internationalization is not the main concern.
* <p>
* To obtain standard formats for a given locale, use the factory methods
* on NumberFormat such as getNumberInstance. These factories will
* return the most appropriate sub-class of NumberFormat for a given
* locale.
*
* @see java.text.NumberFormat#getInstance
* @see java.text.NumberFormat#getNumberInstance
* @see java.text.NumberFormat#getCurrencyInstance
* @see java.text.NumberFormat#getPercentInstance
*/
public DecimalFormat() {
// Get the pattern for the default locale.
Locale def = Locale.getDefault(Locale.Category.FORMAT);
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def);
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
String[] all = adapter.getLocaleResources(def).getNumberPatterns();
// Always applyPattern after the symbols are set
this.symbols = DecimalFormatSymbols.getInstance(def);
applyPattern(all[0], false);
}
示例13: getInstance
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
/**
* Gets the <code>DecimalFormatSymbols</code> instance for the specified
* locale. This method provides access to <code>DecimalFormatSymbols</code>
* instances for locales supported by the Java runtime itself as well
* as for those supported by installed
* {@link java.text.spi.DecimalFormatSymbolsProvider
* DecimalFormatSymbolsProvider} implementations.
* If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
* for the numbering system, the instance is initialized with the specified numbering
* system if the JRE implementation supports it. For example,
* <pre>
* NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
* </pre>
* This may return a {@code NumberFormat} instance with the Thai numbering system,
* instead of the Latin numbering system.
*
* @param locale the desired locale.
* @return a <code>DecimalFormatSymbols</code> instance.
* @exception NullPointerException if <code>locale</code> is null
* @since 1.6
*/
public static final DecimalFormatSymbols getInstance(Locale locale) {
LocaleProviderAdapter adapter;
adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();
DecimalFormatSymbols dfsyms = provider.getInstance(locale);
if (dfsyms == null) {
provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();
dfsyms = provider.getInstance(locale);
}
return dfsyms;
}