当前位置: 首页>>代码示例>>Java>>正文


Java LocaleData.getCurrencyNames方法代码示例

本文整理汇总了Java中sun.util.resources.LocaleData.getCurrencyNames方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleData.getCurrencyNames方法的具体用法?Java LocaleData.getCurrencyNames怎么用?Java LocaleData.getCurrencyNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.util.resources.LocaleData的用法示例。


在下文中一共展示了LocaleData.getCurrencyNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
    }
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:40,代码来源:Currency.java

示例2: 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, (OpenListResourceBundle)null,
                                currencyCode, SYMBOL);
            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;
    }
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:41,代码来源:Currency.java

示例3: getDisplayName

import sun.util.resources.LocaleData; //导入方法依赖的package包/类
/**
 * Gets the name that is suitable for displaying this currency for
 * the specified locale.  If there is no suitable display name found
 * for the specified locale, the ISO 4217 currency code is returned.
 *
 * @param locale the locale for which a display name for this currency is
 * needed
 * @return the display name of this currency for the specified locale
 * @exception NullPointerException if <code>locale</code> is null
 * @since 1.7
 */
public String getDisplayName(Locale locale) {
    try {
        OpenListResourceBundle bundle = LocaleData.getCurrencyNames(locale);
        String result = null;
        String bundleKey = currencyCode.toLowerCase(Locale.ROOT);

        // 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()) {
            result = pool.getLocalizedObject(
                                CurrencyNameGetter.INSTANCE,
                                locale, bundleKey, bundle, currencyCode, DISPLAYNAME);
        }

        if (result == null) {
            result = bundle.getString(bundleKey);
        }

        if (result != null) {
            return result;
        }
    } catch (MissingResourceException e) {
        // fall through
    }

    // use currency code as symbol of last resort
    return currencyCode;
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:42,代码来源:Currency.java


注:本文中的sun.util.resources.LocaleData.getCurrencyNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。