java.util.Locale.LanguageRange Java Examples

The following examples show how to use java.util.Locale.LanguageRange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bug8040211.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example #2
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean areEqual(List<LanguageRange> expected,
        List<LanguageRange> got) {

    boolean error = false;
    if (expected.equals(got)) {
        return !error;
    }

    List<LanguageRange> cloneExpected = new ArrayList<>(expected);
    cloneExpected.removeAll(got);
    if (!cloneExpected.isEmpty()) {
        error = true;
        System.err.println("Found missing range(s): " + cloneExpected);
    }

    // not creating the 'got' clone as the list will not be used after this
    got.removeAll(expected);
    if (!got.isEmpty()) {
        error = true;
        System.err.println("Found extra range(s): " + got);
    }
    return !error;
}
 
Example #3
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testMapEquivalents() {

        String ranges = "HI-IN";
        List<LanguageRange> priorityList = LanguageRange.parse(ranges);
        HashMap<String, List<String>> map = new LinkedHashMap<>();
        List<String> equivalentList = new ArrayList<>();
        equivalentList.add("HI");
        equivalentList.add("HI-Deva");
        map.put("HI", equivalentList);

        List<LanguageRange> expected = new ArrayList<>();
        expected.add(new LanguageRange("hi-in"));
        expected.add(new LanguageRange("hi-deva-in"));
        List<LanguageRange> got
                = LanguageRange.mapEquivalents(priorityList, map);

        if (!areEqual(expected, got)) {
            System.err.println("testMapEquivalents() failed");
            err = true;
        }

    }
 
Example #4
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx";
    String tags = "de-DE, gti, he, nyc, mwj, vaj";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example #5
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example #6
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example #7
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example #8
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example #9
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx, kzj";
    String tags = "de-DE, gti, he, nyc, mwj, vaj, ktr, dtp";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, ktr, dtp, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example #10
Source File: Bug8040211.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx, kzj";
    String tags = "de-DE, gti, he, nyc, mwj, vaj, ktr, dtp";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, ktr, dtp, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example #11
Source File: Bug8040211.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example #12
Source File: Bug8040211.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example #13
Source File: Bug8040211.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example #14
Source File: Bug8040211.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx, kzj";
    String tags = "de-DE, gti, he, nyc, mwj, vaj, ktr, dtp";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, ktr, dtp, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example #15
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example #16
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example #17
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx, kzj";
    String tags = "de-DE, gti, he, nyc, mwj, vaj, ktr, dtp";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, ktr, dtp, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example #18
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testFilter(FilteringMode mode) {

        String ranges = "hi-IN, itc-Ital";
        String tags = "hi-IN, itc-Ital";
        List<LanguageRange> priorityList = LanguageRange.parse(ranges);
        List<Locale> tagList = generateLocales(tags);
        String actualLocales = showLocales(Locale.filter(priorityList, tagList, mode));
        String expectedLocales = "hi-IN, itc-Ital";

        if (!expectedLocales.equals(actualLocales)) {
            System.err.println("testFilter(" + mode + ") failed on language ranges:"
                    + " [" + ranges + "] and language tags: [" + tags + "]");
            err = true;
        }
    }
 
Example #19
Source File: HttpHeadersUtil.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
public static List<String> getAcceptedLocaleNameOrderedByPriority(String acceptLanguageHeader) {
    if(acceptLanguageHeader == null) {
        return Collections.emptyList();
    }
    return LanguageRange.parse(acceptLanguageHeader)
            .stream()
            .map(l -> Locale.forLanguageTag(l.getRange()).getLanguage())
            .distinct()
            .collect(Collectors.toList());
}
 
Example #20
Source File: HttpHeadersUtil.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
public static List<String> getAcceptedLocaleNameOrderedByPriority(String acceptLanguageHeader) {
    if(acceptLanguageHeader == null) {
        return Collections.emptyList();
    }
    return LanguageRange.parse(acceptLanguageHeader)
            .stream()
            .map(l -> Locale.forLanguageTag(l.getRange()).getLanguage())
            .distinct()
            .collect(Collectors.toList());
}
 
Example #21
Source File: AcceptLanguageLocaleResolver.java    From nubes with Apache License 2.0 5 votes vote down vote up
@Override
public Locale resolve(RoutingContext context, List<Locale> availableLocales) {
  String accept = context.request().getHeader(ACCEPT_LANGUAGE.toString());
  if (accept == null) {
    return null;
  }
  List<LanguageRange> ranges = LanguageRange.parse(accept);
  if (ranges.isEmpty()) {
    return null;
  }
  return Locale.lookup(ranges, availableLocales);
}
 
Example #22
Source File: ChainRequestGatewayFilterFactory.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public GatewayFilter apply(Config config) {
    return (exchange, chain) -> {
        return client.get()
            .uri(config.getLanguageServiceEndpoint())
            .exchange()
            .flatMap(response -> {
                return (response.statusCode()
                    .is2xxSuccessful()) ? response.bodyToMono(String.class) : Mono.just(config.getDefaultLanguage());
            })
            .map(LanguageRange::parse)
            .map(range -> {
                exchange.getRequest()
                    .mutate()
                    .headers(h -> h.setAcceptLanguage(range));

                String allOutgoingRequestLanguages = exchange.getRequest()
                    .getHeaders()
                    .getAcceptLanguage()
                    .stream()
                    .map(r -> r.getRange())
                    .collect(Collectors.joining(","));

                logger.info("Chain Request output - Request contains Accept-Language header: " + allOutgoingRequestLanguages);

                return exchange;
            })
            .flatMap(chain::filter);

    };
}
 
Example #23
Source File: Bug8026766.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    LanguageRange lr1 = new LanguageRange("ja", 1.0);
    LanguageRange lr2 = new LanguageRange("fr", 0.0);

    if (!lr1.toString().equals("ja") ||
        !lr2.toString().equals("fr;q=0.0")) {
        throw new RuntimeException("LanguageRange.toString() returned an unexpected result.");
    }
}
 
Example #24
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testLookup() {
    boolean error = false;
    String ranges = "hi-IN, itc-Ital";
    String tags = "hi-IN, itc-Ital";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    Locale actualLocale
            = Locale.lookup(priorityList, localeList);
    String actualLocaleString = "";

    if (actualLocale != null) {
        actualLocaleString = actualLocale.toLanguageTag();
    } else {
        error = true;
    }

    String expectedLocale = "hi-IN";

    if (!expectedLocale.equals(actualLocaleString)) {
        error = true;
    }

    if (error) {
        System.err.println("testLookup() failed on language ranges:"
                + " [" + ranges + "] and language tags: [" + tags + "]");
        err = true;
    }

}
 
Example #25
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testParse() {
    String ranges = "HI-Deva, ja-hIrA-JP, RKI";
    try {
        LanguageRange.parse(ranges);
    } catch (Exception ex) {
        System.err.println("[testParse() failed on range string: "
                + ranges + "] due to "+ex);
        err = true;
    }
}
 
Example #26
Source File: ResteasyContextLocaleResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Optional<List<LanguageRange>> getAcceptableLanguages() {
    HttpHeaders httpHeaders = ResteasyContext.getContextData(HttpHeaders.class);
    if (httpHeaders != null) {
        List<String> acceptLanguageList = httpHeaders.getRequestHeader("Accept-Language");
        if (acceptLanguageList != null && !acceptLanguageList.isEmpty()) {
            return Optional.of(LanguageRange.parse(acceptLanguageList.get(0)));
        }
    }

    return Optional.empty();
}
 
Example #27
Source File: ResteasyContextLocaleResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Locale resolve(LocaleResolverContext context) {
    Optional<List<LanguageRange>> localePriorities = getAcceptableLanguages();
    if (!localePriorities.isPresent()) {
        return context.getDefaultLocale();
    }

    List<Locale> resolvedLocales = Locale.filter(localePriorities.get(), context.getSupportedLocales());
    if (resolvedLocales.size() > 0) {
        return resolvedLocales.get(0);
    }

    return context.getDefaultLocale();
}
 
Example #28
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void test_parse() {
    boolean error = false;
    String str = "Accept-Language: aam, adp, aue, ema, en-gb-oed,"
            + " gti, koj, kwq, kxe, lii, lmm, mtm, ngv, oyb, phr, pub,"
            + " suj, taj;q=0.9, yug;q=0.5, gfx;q=0.4";
    ArrayList<LanguageRange> expected = new ArrayList<>();
    expected.add(new LanguageRange("aam", 1.0));
    expected.add(new LanguageRange("aas", 1.0));
    expected.add(new LanguageRange("adp", 1.0));
    expected.add(new LanguageRange("dz", 1.0));
    expected.add(new LanguageRange("aue", 1.0));
    expected.add(new LanguageRange("ktz", 1.0));
    expected.add(new LanguageRange("ema", 1.0));
    expected.add(new LanguageRange("uok", 1.0));
    expected.add(new LanguageRange("en-gb-oed", 1.0));
    expected.add(new LanguageRange("en-gb-oxendict", 1.0));
    expected.add(new LanguageRange("gti", 1.0));
    expected.add(new LanguageRange("nyc", 1.0));
    expected.add(new LanguageRange("koj", 1.0));
    expected.add(new LanguageRange("kwv", 1.0));
    expected.add(new LanguageRange("kwq", 1.0));
    expected.add(new LanguageRange("yam", 1.0));
    expected.add(new LanguageRange("kxe", 1.0));
    expected.add(new LanguageRange("tvd", 1.0));
    expected.add(new LanguageRange("lii", 1.0));
    expected.add(new LanguageRange("raq", 1.0));
    expected.add(new LanguageRange("lmm", 1.0));
    expected.add(new LanguageRange("rmx", 1.0));
    expected.add(new LanguageRange("mtm", 1.0));
    expected.add(new LanguageRange("ymt", 1.0));
    expected.add(new LanguageRange("ngv", 1.0));
    expected.add(new LanguageRange("nnx", 1.0));
    expected.add(new LanguageRange("oyb", 1.0));
    expected.add(new LanguageRange("thx", 1.0));
    expected.add(new LanguageRange("phr", 1.0));
    expected.add(new LanguageRange("pmu", 1.0));
    expected.add(new LanguageRange("pub", 1.0));
    expected.add(new LanguageRange("puz", 1.0));
    expected.add(new LanguageRange("suj", 1.0));
    expected.add(new LanguageRange("xsj", 1.0));
    expected.add(new LanguageRange("taj", 0.9));
    expected.add(new LanguageRange("tsf", 0.9));
    expected.add(new LanguageRange("yug", 0.5));
    expected.add(new LanguageRange("yuu", 0.5));
    expected.add(new LanguageRange("gfx", 0.4));
    expected.add(new LanguageRange("oun", 0.4));
    expected.add(new LanguageRange("mwj", 0.4));
    expected.add(new LanguageRange("vaj", 0.4));
    List<LanguageRange> got = LanguageRange.parse(str);
    if (!areEqual(expected, got)) {
        error = true;
        System.err.println("    language parse() test failed.");
    }

    if (error) {
        err = true;
        System.err.println("  test_parse() failed.");
    } else {
        System.out.println("  test_parse() passed.");
    }

}
 
Example #29
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void test_filter() {
    boolean error = false;

    String ranges = "mtm-RU, en-gb-oed";
    String tags = "de-DE, en, mtm-RU, ymt-RU, en-gb-oxendict, ja-JP";
    FilteringMode mode = EXTENDED_FILTERING;

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> tagList = generateLocales(tags);
    String actualLocales
            = showLocales(Locale.filter(priorityList, tagList, mode));
    String expectedLocales = "mtm-RU, ymt-RU, en-GB-oxendict";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#1 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    ranges = "phr-*-IN, ja-JP";
    tags = "en, pmu-Guru-IN, ja-Latn-JP, iw";
    mode = EXTENDED_FILTERING;

    priorityList = LanguageRange.parse(ranges);
    tagList = generateLocales(tags);
    actualLocales = showLocales(Locale.filter(priorityList, tagList, mode));
    expectedLocales = "pmu-Guru-IN, ja-Latn-JP";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#2 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    if (error) {
        err = true;
        System.out.println("  test_filter() failed.");
    } else {
        System.out.println("  test_filter() passed.");
    }
}
 
Example #30
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void test_parse() {
    boolean error = false;
    String str = "Accept-Language: aam, adp, aue, bcg, cqu, ema,"
            + " en-gb-oed, gti, kdz, koj, kwq, kxe, lii, lmm, mtm, ngv,"
            + " oyb, phr, pub, suj, taj;q=0.9, ar-hyw;q=0.8, yug;q=0.5, gfx;q=0.4";
    ArrayList<LanguageRange> expected = new ArrayList<>();
    expected.add(new LanguageRange("aam", 1.0));
    expected.add(new LanguageRange("aas", 1.0));
    expected.add(new LanguageRange("adp", 1.0));
    expected.add(new LanguageRange("dz", 1.0));
    expected.add(new LanguageRange("aue", 1.0));
    expected.add(new LanguageRange("ktz", 1.0));
    expected.add(new LanguageRange("bcg", 1.0));
    expected.add(new LanguageRange("bgm", 1.0));
    expected.add(new LanguageRange("cqu", 1.0));
    expected.add(new LanguageRange("quh", 1.0));
    expected.add(new LanguageRange("ema", 1.0));
    expected.add(new LanguageRange("uok", 1.0));
    expected.add(new LanguageRange("en-gb-oed", 1.0));
    expected.add(new LanguageRange("en-gb-oxendict", 1.0));
    expected.add(new LanguageRange("gti", 1.0));
    expected.add(new LanguageRange("nyc", 1.0));
    expected.add(new LanguageRange("kdz", 1.0));
    expected.add(new LanguageRange("ncp", 1.0));
    expected.add(new LanguageRange("koj", 1.0));
    expected.add(new LanguageRange("kwv", 1.0));
    expected.add(new LanguageRange("kwq", 1.0));
    expected.add(new LanguageRange("yam", 1.0));
    expected.add(new LanguageRange("kxe", 1.0));
    expected.add(new LanguageRange("tvd", 1.0));
    expected.add(new LanguageRange("lii", 1.0));
    expected.add(new LanguageRange("raq", 1.0));
    expected.add(new LanguageRange("lmm", 1.0));
    expected.add(new LanguageRange("rmx", 1.0));
    expected.add(new LanguageRange("mtm", 1.0));
    expected.add(new LanguageRange("ymt", 1.0));
    expected.add(new LanguageRange("ngv", 1.0));
    expected.add(new LanguageRange("nnx", 1.0));
    expected.add(new LanguageRange("oyb", 1.0));
    expected.add(new LanguageRange("thx", 1.0));
    expected.add(new LanguageRange("skk", 1.0));
    expected.add(new LanguageRange("jeg", 1.0));
    expected.add(new LanguageRange("phr", 1.0));
    expected.add(new LanguageRange("pmu", 1.0));
    expected.add(new LanguageRange("pub", 1.0));
    expected.add(new LanguageRange("puz", 1.0));
    expected.add(new LanguageRange("suj", 1.0));
    expected.add(new LanguageRange("xsj", 1.0));
    expected.add(new LanguageRange("taj", 0.9));
    expected.add(new LanguageRange("tsf", 0.9));
    expected.add(new LanguageRange("ar-hyw", 0.8));
    expected.add(new LanguageRange("yug", 0.5));
    expected.add(new LanguageRange("yuu", 0.5));
    expected.add(new LanguageRange("gfx", 0.4));
    expected.add(new LanguageRange("oun", 0.4));
    expected.add(new LanguageRange("mwj", 0.4));
    expected.add(new LanguageRange("vaj", 0.4));
    List<LanguageRange> got = LanguageRange.parse(str);
    if (!areEqual(expected, got)) {
        error = true;
        System.err.println("    language parse() test failed.");
    }

    if (error) {
        err = true;
        System.err.println("  test_parse() failed.");
    } else {
        System.out.println("  test_parse() passed.");
    }

}