java.util.Locale.filter()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中java.util.Locale.filter()方法的一些代码示例,展示了Locale.filter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.filter()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:filter

Locale.filter介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

List<Locale.LanguageRange> list1 = new ArrayList<>();
list1.add(new Locale.LanguageRange("*-*"));
// Locales
List<Locale> list3 = Locale.filter(list1,Arrays.asList(Locale.getAvailableLocales()));
list3.forEach(System.out::println);

代码示例来源:origin: stackoverflow.com

Collection<Locale> locales = Arrays.asList(Locale.forLanguageTag("en"),
  Locale.forLanguageTag("en-GB"), Locale.forLanguageTag("en-US"));
List<Locale> filtered = Locale.filter(
  Locale.LanguageRange.parse("en-US;q=1.0,en-GB;q=1.0"), locales);
System.out.println("filtered: "+filtered);

代码示例来源:origin: stackoverflow.com

List<Locale> filtered = Locale.filter(
  Locale.LanguageRange.parse("en-US;q=1.0,en-GB;q=1.0"), locales);
System.out.println("filtered: "+filtered);

代码示例来源:origin: org.wso2.carbon.uis/org.wso2.carbon.uis

/**
   * Returns the best matching locale chosen from a set of available locales for the given language ranges.
   *
   * @param languageRanges   a list of comma-separated language ranges or a list of language ranges in the form of the
   *                         "Accept-Language" header defined in
   *                         <a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC
   *                         2616</a>
   * @param availableLocales available locales to choose from
   * @return Locale the best matching locale, or {@code null} if nothing matches
   */
  public static Locale getMatchingLocale(String languageRanges, Set<Locale> availableLocales) {
    if ((languageRanges == null) || languageRanges.isEmpty()) {
      return null;
    }

    List<Locale> matchingLocales;
    try {
      matchingLocales = Locale.filter(Locale.LanguageRange.parse(languageRanges), availableLocales);
    } catch (IllegalArgumentException e) {
      // languageRanges is ill formed
      return null;
    }
    return matchingLocales.isEmpty() ? null : matchingLocales.get(0);
  }
}

代码示例来源:origin: org.wso2.carbon.uiserver/org.wso2.carbon.uiserver

/**
   * Returns the best matching locale chosen from a set of available locales for the given language ranges.
   *
   * @param languageRanges   a list of comma-separated language ranges or a list of language ranges in the form of the
   *                         "Accept-Language" header defined in
   *                         <a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC
   *                         2616</a>
   * @param availableLocales available locales to choose from
   * @return Locale the best matching locale, or {@code null} if nothing matches
   */
  public static Locale getMatchingLocale(String languageRanges, Set<Locale> availableLocales) {
    if ((languageRanges == null) || languageRanges.isEmpty()) {
      return null;
    }

    List<Locale> matchingLocales;
    try {
      matchingLocales = Locale.filter(Locale.LanguageRange.parse(languageRanges), availableLocales);
    } catch (IllegalArgumentException e) {
      // languageRanges is ill formed
      return null;
    }
    return matchingLocales.isEmpty() ? null : matchingLocales.get(0);
  }
}

相关文章