java.util.Locale#stripExtensions ( )源码实例Demo

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

源代码1 项目: jdk8u_jdk   文件: HostLocaleProviderAdapterImpl.java
private static boolean isSupportedNativeDigitLocale(Locale locale) {
    // special case for th_TH_TH
    if (JRELocaleConstants.TH_TH_TH.equals(locale)) {
        return isNativeDigit("th-TH");
    }

    String numtype = null;
    Locale base = locale;
    if (locale.hasExtensions()) {
        numtype = locale.getUnicodeLocaleType("nu");
        base = locale.stripExtensions();
    }

    if (supportedLocaleSet.contains(base)) {
        // Only supports Latin or Thai (in thai locales) digits.
        if (numtype == null || numtype.equals("latn")) {
            return true;
        } else if (locale.getLanguage().equals("th")) {
            return "thai".equals(numtype) &&
                   isNativeDigit(locale.toLanguageTag());
        }
    }

    return false;
}
 
private static boolean isSupportedNativeDigitLocale(Locale locale) {
    // special case for th_TH_TH
    if (JRELocaleConstants.TH_TH_TH.equals(locale)) {
        return isNativeDigit("th-TH");
    }

    String numtype = null;
    Locale base = locale;
    if (locale.hasExtensions()) {
        numtype = locale.getUnicodeLocaleType("nu");
        base = locale.stripExtensions();
    }

    if (supportedLocaleSet.contains(base)) {
        // Only supports Latin or Thai (in thai locales) digits.
        if (numtype == null || numtype.equals("latn")) {
            return true;
        } else if (locale.getLanguage().equals("th")) {
            return "thai".equals(numtype) &&
                   isNativeDigit(locale.toLanguageTag());
        }
    }

    return false;
}
 
源代码3 项目: jdk8u60   文件: HostLocaleProviderAdapterImpl.java
private static boolean isSupportedNativeDigitLocale(Locale locale) {
    // special case for th_TH_TH
    if (JRELocaleConstants.TH_TH_TH.equals(locale)) {
        return isNativeDigit("th-TH");
    }

    String numtype = null;
    Locale base = locale;
    if (locale.hasExtensions()) {
        numtype = locale.getUnicodeLocaleType("nu");
        base = locale.stripExtensions();
    }

    if (supportedLocaleSet.contains(base)) {
        // Only supports Latin or Thai (in thai locales) digits.
        if (numtype == null || numtype.equals("latn")) {
            return true;
        } else if (locale.getLanguage().equals("th")) {
            return "thai".equals(numtype) &&
                   isNativeDigit(locale.toLanguageTag());
        }
    }

    return false;
}
 
private static boolean isSupportedNativeDigitLocale(Locale locale) {
    // special case for th_TH_TH
    if (JRELocaleConstants.TH_TH_TH.equals(locale)) {
        return isNativeDigit("th-TH");
    }

    String numtype = null;
    Locale base = locale;
    if (locale.hasExtensions()) {
        numtype = locale.getUnicodeLocaleType("nu");
        base = locale.stripExtensions();
    }

    if (supportedLocaleSet.contains(base)) {
        // Only supports Latin or Thai (in thai locales) digits.
        if (numtype == null || numtype.equals("latn")) {
            return true;
        } else if (locale.getLanguage().equals("th")) {
            return "thai".equals(numtype) &&
                   isNativeDigit(locale.toLanguageTag());
        }
    }

    return false;
}
 
源代码5 项目: Bytecoder   文件: SPILocaleProviderAdapter.java
default public boolean isSupportedLocaleDelegate(Locale locale) {
    Map<Locale, P> map = getDelegateMap();
    Locale override = CalendarDataUtility.findRegionOverride(locale);

    // First, call the method with extensions (if any)
    P impl = map.get(override);
    if (impl != null) {
        return impl.isSupportedLocale(override);
    } else {
        // The default behavior
        Locale overrideNoExt = override.stripExtensions();
        impl = map.get(overrideNoExt);
        if (impl != null) {
            return Arrays.stream(impl.getAvailableLocales())
                        .anyMatch(overrideNoExt::equals);
        }
    }

    return false;
}
 
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
源代码7 项目: TencentKona-8   文件: CalendarNameProviderImpl.java
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
源代码8 项目: jdk8u-jdk   文件: CalendarNameProviderImpl.java
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
源代码9 项目: hottub   文件: CalendarNameProviderImpl.java
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
源代码10 项目: openjdk-jdk8u   文件: CalendarNameProviderImpl.java
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
源代码12 项目: cuba   文件: LocaleResolver.java
/**
 * @return A string representation of the Locale without {@code Extension}
 * or a BCP47 language tag if locale object contains {@code Script}
 */
public static String localeToString(Locale locale) {
    if (locale == null) {
        return null;
    }
    Locale strippedLocale = locale.stripExtensions();
    return StringUtils.isEmpty(strippedLocale.getScript()) ?
            strippedLocale.toString() : strippedLocale.toLanguageTag();
}
 
源代码13 项目: openjdk-jdk9   文件: CalendarNameProviderImpl.java
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    if (type == LocaleProviderAdapter.Type.JRE) {
        String oldname = locale.toString().replace('_', '-');
        return langtags.contains(oldname);
    }
    return false;
}
 
源代码14 项目: Bytecoder   文件: CalendarNameProviderImpl.java
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }

    if (calendarType != null) {
        switch (calendarType) {
        case "buddhist":
        case "japanese":
        case "gregory":
        case "islamic":
        case "roc":
            break;
        default:
            // Unknown calendar type
            return false;
        }
    }
    if (langtags.contains(locale.toLanguageTag())) {
        return true;
    }
    String oldname = locale.toString().replace('_', '-');
    return langtags.contains(oldname);
}
 
源代码15 项目: dragonwell8_jdk   文件: LocaleServiceProvider.java
/**
     * Returns {@code true} if the given {@code locale} is supported by
     * this locale service provider. The given {@code locale} may contain
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
     * taken into account for the support determination.
     *
     * <p>The default implementation returns {@code true} if the given {@code locale}
     * is equal to any of the available {@code Locale}s returned by
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
     * given {@code locale} and the available locales. Concrete locale service
     * provider implementations should override this method if those
     * implementations are {@code Locale} extensions-aware. For example,
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
     * extensions in the given {@code locale} to see if any numbering system is
     * specified and can be supported. However, {@code CollatorProvider}
     * implementations may not be affected by any particular numbering systems,
     * and in that case, extensions for numbering systems should be ignored.
     *
     * @param locale a {@code Locale} to be tested
     * @return {@code true} if the given {@code locale} is supported by this
     *         provider; {@code false} otherwise.
     * @throws NullPointerException
     *         if the given {@code locale} is {@code null}
     * @see Locale#hasExtensions()
     * @see Locale#stripExtensions()
     * @since 1.8
     */
    public boolean isSupportedLocale(Locale locale) {
        locale = locale.stripExtensions(); // throws NPE if locale == null
        for (Locale available : getAvailableLocales()) {
            if (locale.equals(available.stripExtensions())) {
                return true;
}
        }
        return false;
    }
 
源代码16 项目: jdk8u-jdk   文件: LocaleServiceProvider.java
/**
     * Returns {@code true} if the given {@code locale} is supported by
     * this locale service provider. The given {@code locale} may contain
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
     * taken into account for the support determination.
     *
     * <p>The default implementation returns {@code true} if the given {@code locale}
     * is equal to any of the available {@code Locale}s returned by
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
     * given {@code locale} and the available locales. Concrete locale service
     * provider implementations should override this method if those
     * implementations are {@code Locale} extensions-aware. For example,
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
     * extensions in the given {@code locale} to see if any numbering system is
     * specified and can be supported. However, {@code CollatorProvider}
     * implementations may not be affected by any particular numbering systems,
     * and in that case, extensions for numbering systems should be ignored.
     *
     * @param locale a {@code Locale} to be tested
     * @return {@code true} if the given {@code locale} is supported by this
     *         provider; {@code false} otherwise.
     * @throws NullPointerException
     *         if the given {@code locale} is {@code null}
     * @see Locale#hasExtensions()
     * @see Locale#stripExtensions()
     * @since 1.8
     */
    public boolean isSupportedLocale(Locale locale) {
        locale = locale.stripExtensions(); // throws NPE if locale == null
        for (Locale available : getAvailableLocales()) {
            if (locale.equals(available.stripExtensions())) {
                return true;
}
        }
        return false;
    }
 
源代码17 项目: openjdk-8   文件: LocaleServiceProvider.java
/**
     * Returns {@code true} if the given {@code locale} is supported by
     * this locale service provider. The given {@code locale} may contain
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
     * taken into account for the support determination.
     *
     * <p>The default implementation returns {@code true} if the given {@code locale}
     * is equal to any of the available {@code Locale}s returned by
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
     * given {@code locale} and the available locales. Concrete locale service
     * provider implementations should override this method if those
     * implementations are {@code Locale} extensions-aware. For example,
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
     * extensions in the given {@code locale} to see if any numbering system is
     * specified and can be supported. However, {@code CollatorProvider}
     * implementations may not be affected by any particular numbering systems,
     * and in that case, extensions for numbering systems should be ignored.
     *
     * @param locale a {@code Locale} to be tested
     * @return {@code true} if the given {@code locale} is supported by this
     *         provider; {@code false} otherwise.
     * @throws NullPointerException
     *         if the given {@code locale} is {@code null}
     * @see Locale#hasExtensions()
     * @see Locale#stripExtensions()
     * @since 1.8
     */
    public boolean isSupportedLocale(Locale locale) {
        locale = locale.stripExtensions(); // throws NPE if locale == null
        for (Locale available : getAvailableLocales()) {
            if (locale.equals(available.stripExtensions())) {
                return true;
}
        }
        return false;
    }
 
源代码18 项目: jdk8u-dev-jdk   文件: LocaleServiceProvider.java
/**
     * Returns {@code true} if the given {@code locale} is supported by
     * this locale service provider. The given {@code locale} may contain
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
     * taken into account for the support determination.
     *
     * <p>The default implementation returns {@code true} if the given {@code locale}
     * is equal to any of the available {@code Locale}s returned by
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
     * given {@code locale} and the available locales. Concrete locale service
     * provider implementations should override this method if those
     * implementations are {@code Locale} extensions-aware. For example,
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
     * extensions in the given {@code locale} to see if any numbering system is
     * specified and can be supported. However, {@code CollatorProvider}
     * implementations may not be affected by any particular numbering systems,
     * and in that case, extensions for numbering systems should be ignored.
     *
     * @param locale a {@code Locale} to be tested
     * @return {@code true} if the given {@code locale} is supported by this
     *         provider; {@code false} otherwise.
     * @throws NullPointerException
     *         if the given {@code locale} is {@code null}
     * @see Locale#hasExtensions()
     * @see Locale#stripExtensions()
     * @since 1.8
     */
    public boolean isSupportedLocale(Locale locale) {
        locale = locale.stripExtensions(); // throws NPE if locale == null
        for (Locale available : getAvailableLocales()) {
            if (locale.equals(available.stripExtensions())) {
                return true;
}
        }
        return false;
    }
 
源代码19 项目: jdk8u60   文件: LocaleServiceProvider.java
/**
     * Returns {@code true} if the given {@code locale} is supported by
     * this locale service provider. The given {@code locale} may contain
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
     * taken into account for the support determination.
     *
     * <p>The default implementation returns {@code true} if the given {@code locale}
     * is equal to any of the available {@code Locale}s returned by
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
     * given {@code locale} and the available locales. Concrete locale service
     * provider implementations should override this method if those
     * implementations are {@code Locale} extensions-aware. For example,
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
     * extensions in the given {@code locale} to see if any numbering system is
     * specified and can be supported. However, {@code CollatorProvider}
     * implementations may not be affected by any particular numbering systems,
     * and in that case, extensions for numbering systems should be ignored.
     *
     * @param locale a {@code Locale} to be tested
     * @return {@code true} if the given {@code locale} is supported by this
     *         provider; {@code false} otherwise.
     * @throws NullPointerException
     *         if the given {@code locale} is {@code null}
     * @see Locale#hasExtensions()
     * @see Locale#stripExtensions()
     * @since 1.8
     */
    public boolean isSupportedLocale(Locale locale) {
        locale = locale.stripExtensions(); // throws NPE if locale == null
        for (Locale available : getAvailableLocales()) {
            if (locale.equals(available.stripExtensions())) {
                return true;
}
        }
        return false;
    }
 
/**
     * Returns {@code true} if the given {@code locale} is supported by
     * this locale service provider. The given {@code locale} may contain
     * <a href="../Locale.html#def_extensions">extensions</a> that should be
     * taken into account for the support determination.
     *
     * <p>The default implementation returns {@code true} if the given {@code locale}
     * is equal to any of the available {@code Locale}s returned by
     * {@link #getAvailableLocales()} with ignoring any extensions in both the
     * given {@code locale} and the available locales. Concrete locale service
     * provider implementations should override this method if those
     * implementations are {@code Locale} extensions-aware. For example,
     * {@code DecimalFormatSymbolsProvider} implementations will need to check
     * extensions in the given {@code locale} to see if any numbering system is
     * specified and can be supported. However, {@code CollatorProvider}
     * implementations may not be affected by any particular numbering systems,
     * and in that case, extensions for numbering systems should be ignored.
     *
     * @param locale a {@code Locale} to be tested
     * @return {@code true} if the given {@code locale} is supported by this
     *         provider; {@code false} otherwise.
     * @throws NullPointerException
     *         if the given {@code locale} is {@code null}
     * @see Locale#hasExtensions()
     * @see Locale#stripExtensions()
     * @since 1.8
     */
    public boolean isSupportedLocale(Locale locale) {
        locale = locale.stripExtensions(); // throws NPE if locale == null
        for (Locale available : getAvailableLocales()) {
            if (locale.equals(available.stripExtensions())) {
                return true;
}
        }
        return false;
    }