java.util.spi.LocaleServiceProvider源码实例Demo

类java.util.spi.LocaleServiceProvider源码实例Demo

下面列出了java.util.spi.LocaleServiceProvider 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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;
}
 
@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;
}
 
/**
 * 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;
    }
 
源代码4 项目: jdk8u-jdk   文件: AuxLocaleProviderAdapter.java
@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;
}
 
源代码5 项目: jdk8u60   文件: AuxLocaleProviderAdapter.java
@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;
}
 
源代码6 项目: jdk8u60   文件: LocaleServiceProviderPool.java
/**
 * 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;
    }
 
@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;
}
 
源代码8 项目: jdk8u-jdk   文件: AuxLocaleProviderAdapter.java
@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;
}
 
源代码9 项目: openjdk-8   文件: LocaleServiceProviderPool.java
/**
 * 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;
    }
 
源代码10 项目: dragonwell8_jdk   文件: JRELocaleProviderAdapter.java
/**
 * 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");
    }
}
 
源代码11 项目: Bytecoder   文件: LocaleServiceProviderPool.java
@SuppressWarnings("unchecked")
private <P extends LocaleServiceProvider, S> S getLocalizedObjectImpl(LocalizedObjectGetter<P, S> getter,
                                 Locale locale,
                                 boolean isObjectProvider,
                                 String key,
                                 Object... params) {
    if (locale == null) {
        throw new NullPointerException();
    }

    List<Locale> lookupLocales = getLookupLocales(locale);

    for (Locale current : lookupLocales) {
        S providersObj;

        for (LocaleServiceProvider lsp: findProviders(current, isObjectProvider)) {
            providersObj = getter.getObject((P)lsp, locale, key, params);
            if (providersObj != null) {
                return providersObj;
            } else if (isObjectProvider) {
                config(LocaleServiceProviderPool.class,
                    "A locale sensitive service object provider returned null, " +
                    "which should not happen. Provider: " + lsp + " Locale: " + locale);
            }
        }
    }

    // not found.
    return null;
}
 
源代码12 项目: dragonwell8_jdk   文件: AuxLocaleProviderAdapter.java
/**
 * 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;
}
 
源代码13 项目: jdk8u-jdk   文件: LocaleServiceProviderPool.java
/**
 * 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);
            }
        }
    }
}
 
/**
 * 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);
            }
        }
    }
}
 
源代码15 项目: openjdk-8   文件: JRELocaleProviderAdapter.java
/**
 * 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");
    }
}
 
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;
}
 
源代码17 项目: Bytecoder   文件: LocaleServiceProviderPool.java
/**
 * 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;
}
 
源代码18 项目: openjdk-jdk9   文件: HostLocaleProviderAdapter.java
@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;
}
 
源代码19 项目: jdk8u_jdk   文件: LocaleProviderAdapter.java
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;
}
 
源代码20 项目: jdk8u_jdk   文件: SPILocaleProviderAdapter.java
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;
}
 
/**
 * 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;
}
 
源代码22 项目: hottub   文件: LocaleServiceProviderPool.java
/**
 * 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;
}
 
源代码23 项目: TencentKona-8   文件: SPILocaleProviderAdapter.java
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;
}
 
源代码24 项目: jdk8u-jdk   文件: LocaleProviderAdapter.java
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;
}
 
源代码25 项目: jdk8u-jdk   文件: SPILocaleProviderAdapter.java
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;
}
 
源代码26 项目: hottub   文件: SPILocaleProviderAdapter.java
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;
}
 
源代码27 项目: jdk8u-jdk   文件: LocaleServiceProviderPool.java
/**
 * 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;
}
 
源代码28 项目: jdk8u-jdk   文件: LocaleServiceProviderPool.java
/**
 * 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;
}
 
源代码29 项目: openjdk-8   文件: AuxLocaleProviderAdapter.java
/**
 * 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;
}
 
源代码30 项目: Bytecoder   文件: HostLocaleProviderAdapter.java
@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;
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 同包方法