Java Code Examples for java.util.Locale.LanguageRange

The following are Jave code examples for showing how to use LanguageRange of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hybris-integration-intellij-idea-plugin   File: JspPropertyFoldingBuilder.java   View Source Code Vote up 6 votes
private static IProperty chooseForLocale(
    final @NotNull List<Locale.LanguageRange> priorityList,
    final @NotNull List<IProperty> properties
) {
    if (properties.isEmpty()) {
        return null;
    }
    IProperty first = properties.get(0);
    if (properties.size() == 1) {
        return first;
    }
    final Map<Locale, IProperty> map = new HashMap<>();
    final List<Locale> locales = new LinkedList<>();
    for (IProperty nextProperty : properties) {
        Locale nextLocale = safeGetLocale(nextProperty);
        if (nextLocale != null) {
            map.put(nextLocale, nextProperty);
            locales.add(nextLocale);
        }
    }

    Locale best = Locale.lookup(priorityList, locales);
    //System.err.println("found locales: " + locales + ", best: " + best + ", result: " + map.get(best));
    return Optional.ofNullable(best).map(map::get).orElse(first);
}
 
Example 2
Project: openjdk-jdk10   File: Bug8035133.java   View Source Code Vote up 6 votes
private static void checkLookup(String ranges, String tags,
        String expectedLocale) {

    List<Locale.LanguageRange> priorityList = Locale.LanguageRange
            .parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    Locale loc = Locale.lookup(priorityList, localeList);
    String actualLocale
            = loc.toLanguageTag();

    if (!actualLocale.equals(expectedLocale)) {
        System.err.println("Locale.lookup failed with ranges: " + ranges
                + " Expected: " + expectedLocale
                + " Actual: " + actualLocale);
        err = true;
    }

}
 
Example 3
Project: openjdk-jdk10   File: Bug8035133.java   View Source Code Vote up 6 votes
private static void checkFilter(String ranges, String tags,
        String expectedLocales) {

    List<Locale.LanguageRange> priorityList = Locale.LanguageRange
            .parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocales = getLocalesAsString(
            Locale.filter(priorityList, localeList));

    if (!actualLocales.equals(expectedLocales)) {
        System.err.println("Locale.filter failed with ranges: " + ranges
                + " Expected: " + expectedLocales
                + " Actual: " + actualLocales);
        err = true;
    }

}