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


Java LocaleServiceProvider类代码示例

本文整理汇总了Java中java.util.spi.LocaleServiceProvider的典型用法代码示例。如果您正苦于以下问题:Java LocaleServiceProvider类的具体用法?Java LocaleServiceProvider怎么用?Java LocaleServiceProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getAvailableLocales

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        Set<Locale> avail = new HashSet<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:AuxLocaleProviderAdapter.java

示例2: findProviders

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Returns the list of locale service provider instances that support
 * the specified locale.
 *
 * @param locale the given locale
 * @return the list of locale data adapter types
 */
private List<LocaleProviderAdapter.Type> findProviders(Locale locale) {
    List<LocaleProviderAdapter.Type> providersList = providersCache.get(locale);
    if (providersList == null) {
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleServiceProvider lsp = providers.get(type);
            if (lsp != null) {
                if (lsp.isSupportedLocale(locale)) {
                    if (providersList == null) {
                        providersList = new ArrayList<>(2);
                    }
                    providersList.add(type);

                }
            }
        }
        if (providersList == null) {
            providersList = NULL_LIST;
        }
        List<LocaleProviderAdapter.Type> val = providersCache.putIfAbsent(locale, providersList);
        if (val != null) {
            providersList = val;
        }
    }
        return providersList;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:LocaleServiceProviderPool.java

示例3: getAvailableLocales

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
@Override
public Locale[] getAvailableLocales() {
    if (availableLocales == null) {
        List<Locale> avail = new ArrayList<>();
        for (Class<? extends LocaleServiceProvider> c :
                LocaleServiceProviderPool.spiClasses) {
            LocaleServiceProvider lsp = getLocaleServiceProvider(c);
            if (lsp != null) {
                avail.addAll(Arrays.asList(lsp.getAvailableLocales()));
            }
        }
        availableLocales = avail.toArray(new Locale[0]);
    }

    // assuming caller won't mutate the array.
    return availableLocales;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:AuxLocaleProviderAdapter.java

示例4: getAvailableLocaleSet

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Returns the union of locale sets that are available from
 * each service provider. This method does NOT return the
 * defensive copy.
 *
 * @return a set of available locales
 */
private synchronized Set<Locale> getAvailableLocaleSet() {
    if (availableLocales == null) {
        availableLocales = new HashSet<>();
        for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
            LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type);
            if (lda != null) {
                LocaleServiceProvider lsp = lda.getLocaleServiceProvider(providerClass);
                if (lsp != null) {
                    Locale[] locales = lsp.getAvailableLocales();
                    for (Locale locale: locales) {
                        availableLocales.add(getLookupLocale(locale));
                    }
                }
            }
        }
    }

    return availableLocales;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:LocaleServiceProviderPool.java

示例5: getProviderByLocale

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Get provider that support specified locale. If there is no provider
 * found, return <code>null</code>.
 * 
 * @param cache
 *            cached providers
 * @param locale
 *            the specified locale
 * @param providerFileName
 *            provider configuration file name
 * @return <code>LocaleServiceProvider</code> that support the locale
 */
public static LocaleServiceProvider getProviderByLocale(
        HashMap<ClassLoader, Object> cache, Locale locale,
        String providerFileName) {
    HashMap<LocaleServiceProvider, Set<Locale>> providers = getProviders(
            cache, providerFileName);
    // no provider installed
    if (providers == null || providers.size() == 0) {
        return null;
    }

    // find provider
    for (LocaleServiceProvider provider : providers.keySet()) {
        if (providers.get(provider).contains(locale)) {
            return provider;
        }
    }

    // no provider found
    return null;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:33,代码来源:LocaleServiceProviderLoader.java

示例6: getProviderSupportLocales

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Return all locales supported by the installed providers. If no provider
 * installed return <code>null</code>.
 * 
 * @param cache
 *            cached providers
 * @param providerFileName
 *            provider configuration file name
 * @return all locales supported by the installed providers
 */
public static Locale[] getProviderSupportLocales(
        HashMap<ClassLoader, Object> cache, String providerFileName) {

    HashMap<LocaleServiceProvider, Set<Locale>> providers = getProviders(
            cache, providerFileName);

    if (providers == null || providers.size() == 0) {
        return null;
    }

    List<Locale> locales = new ArrayList<Locale>();
    for (Set<Locale> element : providers.values()) {
        locales.addAll(element);
    }

    return locales.toArray(new Locale[0]);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:LocaleServiceProviderLoader.java

示例7: getLocaleServiceProvider

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Getter method for Locale Service Providers
 */
@Override
@SuppressWarnings("unchecked")
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    switch (c.getSimpleName()) {
    case "BreakIteratorProvider":
        return (P) getBreakIteratorProvider();
    case "CollatorProvider":
        return (P) getCollatorProvider();
    case "DateFormatProvider":
        return (P) getDateFormatProvider();
    case "DateFormatSymbolsProvider":
        return (P) getDateFormatSymbolsProvider();
    case "DecimalFormatSymbolsProvider":
        return (P) getDecimalFormatSymbolsProvider();
    case "NumberFormatProvider":
        return (P) getNumberFormatProvider();
    case "CurrencyNameProvider":
        return (P) getCurrencyNameProvider();
    case "LocaleNameProvider":
        return (P) getLocaleNameProvider();
    case "TimeZoneNameProvider":
        return (P) getTimeZoneNameProvider();
    case "CalendarDataProvider":
        return (P) getCalendarDataProvider();
    case "CalendarNameProvider":
        return (P) getCalendarNameProvider();
    case "CalendarProvider":
        return (P) getCalendarProvider();
    default:
        throw new InternalError("should not come down here");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:JRELocaleProviderAdapter.java

示例8: findAdapter

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass,
                                             Locale locale) {
    for (Type type : getAdapterPreference()) {
        LocaleProviderAdapter adapter = forType(type);
        LocaleServiceProvider provider = adapter.getLocaleServiceProvider(providerClass);
        if (provider != null) {
            if (provider.isSupportedLocale(locale)) {
                return adapter;
            }
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:LocaleProviderAdapter.java

示例9: getLocaleServiceProvider

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Getter method for Locale Service Providers
 */
@Override
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    @SuppressWarnings("unchecked")
    P lsp = (P) providersMap.get(c);
    if (lsp == null) {
        lsp = findInstalledProvider(c);
        providersMap.putIfAbsent(c, lsp == null ? NULL_PROVIDER : lsp);
    }

    return lsp;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:AuxLocaleProviderAdapter.java

示例10: findInstalledProvider

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {
    try {
        Method getter = HostLocaleProviderAdapterImpl.class.getMethod(
                "get" + c.getSimpleName(), (Class<?>[]) null);
        return (P)getter.invoke(null, (Object[]) null);
    }  catch (NoSuchMethodException |
              IllegalAccessException |
              IllegalArgumentException |
              InvocationTargetException ex) {
        LocaleServiceProviderPool.config(HostLocaleProviderAdapter.class, ex.toString());
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:HostLocaleProviderAdapter.java

示例11: getPool

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * A factory method that returns a singleton instance
 */
public static LocaleServiceProviderPool getPool(Class<? extends LocaleServiceProvider> providerClass) {
    LocaleServiceProviderPool pool = poolOfPools.get(providerClass);
    if (pool == null) {
        LocaleServiceProviderPool newPool =
            new LocaleServiceProviderPool(providerClass);
        pool = poolOfPools.putIfAbsent(providerClass, newPool);
        if (pool == null) {
            pool = newPool;
        }
    }

    return pool;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:LocaleServiceProviderPool.java

示例12: LocaleServiceProviderPool

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * The sole constructor.
 *
 * @param c class of the locale sensitive service
 */
private LocaleServiceProviderPool (final Class<? extends LocaleServiceProvider> c) {
    providerClass = c;

    for (LocaleProviderAdapter.Type type : LocaleProviderAdapter.getAdapterPreference()) {
        LocaleProviderAdapter lda = LocaleProviderAdapter.forType(type);
        if (lda != null) {
            LocaleServiceProvider provider = lda.getLocaleServiceProvider(c);
            if (provider != null) {
                providers.putIfAbsent(type, provider);
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:LocaleServiceProviderPool.java

示例13: getAvailableLocaleSet

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Returns the union of locale sets that are available from
 * each service provider. This method does NOT return the
 * defensive copy.
 *
 * @return a set of available locales
 */
private synchronized Set<Locale> getAvailableLocaleSet() {
    if (availableLocales == null) {
        availableLocales = new HashSet<>();
        for (LocaleServiceProvider lsp : providers.values()) {
            Locale[] locales = lsp.getAvailableLocales();
            for (Locale locale: locales) {
                availableLocales.add(getLookupLocale(locale));
            }
        }
    }

    return availableLocales;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:LocaleServiceProviderPool.java

示例14: getImpl

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
private static <P extends LocaleServiceProvider> P getImpl(Map<Locale, P> map, Locale locale) {
    for (Locale l : LocaleServiceProviderPool.getLookupLocales(locale)) {
        P ret = map.get(l);
        if (ret != null) {
            return ret;
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:SPILocaleProviderAdapter.java

示例15: getLocaleServiceProvider

import java.util.spi.LocaleServiceProvider; //导入依赖的package包/类
/**
 * Getter method for Locale Service Providers
 */
@Override
@SuppressWarnings("unchecked")
public <P extends LocaleServiceProvider> P getLocaleServiceProvider(Class<P> c) {
    switch (c.getSimpleName()) {
    case "BreakIteratorProvider":
        return (P) getBreakIteratorProvider();
    case "CollatorProvider":
        return (P) getCollatorProvider();
    case "DateFormatProvider":
        return (P) getDateFormatProvider();
    case "DateFormatSymbolsProvider":
        return (P) getDateFormatSymbolsProvider();
    case "DecimalFormatSymbolsProvider":
        return (P) getDecimalFormatSymbolsProvider();
    case "NumberFormatProvider":
        return (P) getNumberFormatProvider();
    case "CurrencyNameProvider":
        return (P) getCurrencyNameProvider();
    case "LocaleNameProvider":
        return (P) getLocaleNameProvider();
    case "TimeZoneNameProvider":
        return (P) getTimeZoneNameProvider();
    case "CalendarDataProvider":
        return (P) getCalendarDataProvider();
    case "CalendarNameProvider":
        return (P) getCalendarNameProvider();
    case "CalendarProvider":
        return (P) getCalendarProvider();
    case "JavaTimeDateTimePatternProvider":
        return (P) getJavaTimeDateTimePatternProvider();
    default:
        throw new InternalError("should not come down here");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:JRELocaleProviderAdapter.java


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