本文整理汇总了Java中sun.util.resources.LocaleData类的典型用法代码示例。如果您正苦于以下问题:Java LocaleData类的具体用法?Java LocaleData怎么用?Java LocaleData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocaleData类属于sun.util.resources包,在下文中一共展示了LocaleData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cacheLookup
import sun.util.resources.LocaleData; //导入依赖的package包/类
/**
* Look up resource data for the desiredLocale in the cache; update the
* cache if necessary.
*/
private static ResourceBundle cacheLookup(Locale desiredLocale) {
ResourceBundle rb;
SoftReference data
= (SoftReference)cachedLocaleData.get(desiredLocale);
if (data == null) {
rb = LocaleData.getDateFormatData(desiredLocale);
data = new SoftReference(rb);
cachedLocaleData.put(desiredLocale, data);
} else {
if ((rb = (ResourceBundle)data.get()) == null) {
rb = LocaleData.getDateFormatData(desiredLocale);
data = new SoftReference(rb);
}
}
return rb;
}
示例2: DecimalFormat
import sun.util.resources.LocaleData; //导入依赖的package包/类
/**
* Creates a DecimalFormat using the default pattern and symbols
* for the default 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() {
Locale def = Locale.getDefault();
// try to get the pattern from the cache
String pattern = (String) cachedLocaleData.get(def);
if (pattern == null) { /* cache miss */
// Get the pattern for the default locale.
ResourceBundle rb = LocaleData.getNumberFormatData(def);
String[] all = rb.getStringArray("NumberPatterns");
pattern = all[0];
/* update cache */
cachedLocaleData.put(def, pattern);
}
// Always applyPattern after the symbols are set
this.symbols = new DecimalFormatSymbols(def);
applyPattern(pattern, false);
}
示例3: getDisplayVariant
import sun.util.resources.LocaleData; //导入依赖的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.
*
* @exception NullPointerException if <code>inLocale</code> is <code>null</code>
*/
public String getDisplayVariant(Locale inLocale) {
if (variant.length() == 0)
return "";
OpenListResourceBundle bundle = LocaleData.getLocaleNames(inLocale);
String names[] = getDisplayVariantArray(bundle, inLocale);
// Get the localized patterns for formatting a list, and use
// them to format the list.
String listPattern = null;
String listCompositionPattern = null;
try {
listPattern = bundle.getString("ListPattern");
listCompositionPattern = bundle.getString("ListCompositionPattern");
} catch (MissingResourceException e) {
}
return formatList(names, listPattern, listCompositionPattern);
}
示例4: initializeData
import sun.util.resources.LocaleData; //导入依赖的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.
ResourceBundle resource = LocaleData.getDateFormatData(locale);
eras = resource.getStringArray("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"));
}
示例5: DecimalFormat
import sun.util.resources.LocaleData; //导入依赖的package包/类
/**
* Creates a DecimalFormat using the default pattern and symbols
* for the default 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() {
Locale def = Locale.getDefault(Locale.Category.FORMAT);
// try to get the pattern from the cache
String pattern = cachedLocaleData.get(def);
if (pattern == null) { /* cache miss */
// Get the pattern for the default locale.
ResourceBundle rb = LocaleData.getNumberFormatData(def);
String[] all = rb.getStringArray("NumberPatterns");
pattern = all[0];
/* update cache */
cachedLocaleData.putIfAbsent(def, pattern);
}
// Always applyPattern after the symbols are set
this.symbols = new DecimalFormatSymbols(def);
applyPattern(pattern, false);
}
示例6: getDisplayVariant
import sun.util.resources.LocaleData; //导入依赖的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.
*
* @exception NullPointerException if <code>inLocale</code> is <code>null</code>
*/
public String getDisplayVariant(Locale inLocale) {
if (baseLocale.getVariant().length() == 0)
return "";
OpenListResourceBundle bundle = LocaleData.getLocaleNames(inLocale);
String names[] = getDisplayVariantArray(bundle, inLocale);
// Get the localized patterns for formatting a list, and use
// them to format the list.
String listPattern = null;
String listCompositionPattern = null;
try {
listPattern = bundle.getString("ListPattern");
listCompositionPattern = bundle.getString("ListCompositionPattern");
} catch (MissingResourceException e) {
}
return formatList(names, listPattern, listCompositionPattern);
}
示例7: getDisplayName
import sun.util.resources.LocaleData; //导入依赖的package包/类
public String getDisplayName(int field, int style, Locale locale) {
if (field != ERA) {
return super.getDisplayName(field, style, locale);
}
// Handle Thai BuddhistCalendar specific era names
if (field < 0 || field >= fields.length ||
style < SHORT || style > LONG) {
throw new IllegalArgumentException();
}
if (locale == null) {
throw new NullPointerException();
}
ResourceBundle rb = LocaleData.getDateFormatData(locale);
String[] eras = rb.getStringArray(getKey(style));
return eras[get(field)];
}
示例8: getJRELocales
import sun.util.resources.LocaleData; //导入依赖的package包/类
/**
* Returns an array of available locales (already normalized for
* service lookup) supported by the JRE.
* Note that this method does not return a defensive copy.
*
* @return list of the available JRE locales
*/
private List<Locale> getJRELocales() {
if (availableJRELocales == null) {
synchronized (LocaleServiceProviderPool.class) {
if (availableJRELocales == null) {
Locale[] allLocales = LocaleData.getAvailableLocales();
List<Locale> tmpList = new ArrayList<>(allLocales.length);
for (Locale locale : allLocales) {
tmpList.add(getLookupLocale(locale));
}
availableJRELocales = tmpList;
}
}
}
return availableJRELocales;
}
示例9: getInstance
import sun.util.resources.LocaleData; //导入依赖的package包/类
private static NumberFormat getInstance(Locale desiredLocale,
int choice) {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
if (pool.hasProviders()) {
NumberFormat providersInstance = pool.getLocalizedObject(
NumberFormatGetter.INSTANCE,
desiredLocale,
choice);
if (providersInstance != null) {
return providersInstance;
}
}
/* try the cache first */
String[] numberPatterns = (String[])cachedLocaleData.get(desiredLocale);
if (numberPatterns == null) { /* cache miss */
ResourceBundle resource = LocaleData.getNumberFormatData(desiredLocale);
numberPatterns = resource.getStringArray("NumberPatterns");
/* update cache */
cachedLocaleData.put(desiredLocale, numberPatterns);
}
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
format.adjustForCurrencyDefaultFractionDigits();
}
return format;
}
示例10: getDisplayString
import sun.util.resources.LocaleData; //导入依赖的package包/类
private String getDisplayString(String code, Locale inLocale, int type) {
if (code.length() == 0) {
return "";
}
if (inLocale == null) {
throw new NullPointerException();
}
try {
OpenListResourceBundle bundle = LocaleData.getLocaleNames(inLocale);
String key = (type == DISPLAY_VARIANT ? "%%"+code : code);
String result = null;
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(LocaleNameProvider.class);
if (pool.hasProviders()) {
result = pool.getLocalizedObject(
LocaleNameGetter.INSTANCE,
inLocale, bundle, key,
type, code);
}
if (result == null) {
result = bundle.getString(key);
}
if (result != null) {
return result;
}
}
catch (Exception e) {
// just fall through
}
return code;
}
示例11: getSymbol
import sun.util.resources.LocaleData; //导入依赖的package包/类
/**
* Gets the symbol of this currency for the specified locale.
* For example, for the US Dollar, the symbol is "$" if the specified
* locale is the US, while for other locales it may be "US$". If no
* symbol can be determined, the ISO 4217 currency code is returned.
*
* @param locale the locale for which a display name for this currency is
* needed
* @return the symbol of this currency for the specified locale
* @exception NullPointerException if <code>locale</code> is null
*/
public String getSymbol(Locale locale) {
try {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
if (pool.hasProviders()) {
// Assuming that all the country locales include necessary currency
// symbols in the Java runtime's resources, so there is no need to
// examine whether Java runtime's currency resource bundle is missing
// names. Therefore, no resource bundle is provided for calling this
// method.
String symbol = pool.getLocalizedObject(
CurrencyNameGetter.INSTANCE,
locale, null, currencyCode);
if (symbol != null) {
return symbol;
}
}
ResourceBundle bundle = LocaleData.getCurrencyNames(locale);
return bundle.getString(currencyCode);
} catch (MissingResourceException e) {
// use currency code as symbol of last resort
return currencyCode;
}
}
示例12: setWeekCountData
import sun.util.resources.LocaleData; //导入依赖的package包/类
/**
* Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent.
* They are used to figure out the week count for a specific date for
* a given locale. These must be set when a Calendar is constructed.
* @param desiredLocale the given locale.
*/
private void setWeekCountData(Locale desiredLocale)
{
/* try to get the Locale data from the cache */
int[] data = cachedLocaleData.get(desiredLocale);
if (data == null) { /* cache miss */
ResourceBundle bundle = LocaleData.getCalendarData(desiredLocale);
data = new int[2];
data[0] = Integer.parseInt(bundle.getString("firstDayOfWeek"));
data[1] = Integer.parseInt(bundle.getString("minimalDaysInFirstWeek"));
cachedLocaleData.put(desiredLocale, data);
}
firstDayOfWeek = data[0];
minimalDaysInFirstWeek = data[1];
}
示例13: getDisplayName
import sun.util.resources.LocaleData; //导入依赖的package包/类
public String getDisplayName(int field, int style, Locale locale) {
if (!checkDisplayNameParams(field, style, SHORT, LONG, locale,
ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
return null;
}
// "GanNen" is supported only in the LONG style.
if (field == YEAR
&& (style == SHORT || get(YEAR) != 1 || get(ERA) == 0)) {
return null;
}
ResourceBundle rb = LocaleData.getDateFormatData(locale);
String name = null;
String key = getKey(field, style);
if (key != null) {
String[] strings = rb.getStringArray(key);
if (field == YEAR) {
if (strings.length > 0) {
name = strings[0];
}
} else {
int index = get(field);
// If the ERA value is out of range for strings, then
// try to get its name or abbreviation from the Era instance.
if (field == ERA && index >= strings.length && index < eras.length) {
Era era = eras[index];
name = (style == SHORT) ? era.getAbbreviation() : era.getName();
} else {
if (field == DAY_OF_WEEK)
--index;
name = strings[index];
}
}
}
return name;
}
示例14: getDisplayNamesImpl
import sun.util.resources.LocaleData; //导入依赖的package包/类
private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
ResourceBundle rb = LocaleData.getDateFormatData(locale);
String key = getKey(field, style);
Map<String,Integer> map = new HashMap<String,Integer>();
if (key != null) {
String[] strings = rb.getStringArray(key);
if (field == YEAR) {
if (strings.length > 0) {
map.put(strings[0], 1);
}
} else {
int base = (field == DAY_OF_WEEK) ? 1 : 0;
for (int i = 0; i < strings.length; i++) {
map.put(strings[i], base + i);
}
// If strings[] has fewer than eras[], get more names from eras[].
if (field == ERA && strings.length < eras.length) {
for (int i = strings.length; i < eras.length; i++) {
Era era = eras[i];
String name = (style == SHORT) ? era.getAbbreviation() : era.getName();
map.put(name, i);
}
}
}
}
return map.size() > 0 ? map : null;
}
示例15: getInstance
import sun.util.resources.LocaleData; //导入依赖的package包/类
private static NumberFormat getInstance(Locale desiredLocale,
int choice) {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
if (pool.hasProviders()) {
NumberFormat providersInstance = pool.getLocalizedObject(
NumberFormatGetter.INSTANCE,
desiredLocale,
choice);
if (providersInstance != null) {
return providersInstance;
}
}
/* try the cache first */
String[] numberPatterns = (String[])cachedLocaleData.get(desiredLocale);
if (numberPatterns == null) { /* cache miss */
ResourceBundle resource = LocaleData.getNumberFormatData(desiredLocale);
numberPatterns = resource.getStringArray("NumberPatterns");
/* update cache */
cachedLocaleData.put(desiredLocale, numberPatterns);
}
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
format.adjustForCurrencyDefaultFractionDigits();
}
return format;
}