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

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

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

Locale.filter介绍

暂无

代码示例

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

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

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

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

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

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

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

  1. /**
  2. * Returns the best matching locale chosen from a set of available locales for the given language ranges.
  3. *
  4. * @param languageRanges a list of comma-separated language ranges or a list of language ranges in the form of the
  5. * "Accept-Language" header defined in
  6. * <a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC
  7. * 2616</a>
  8. * @param availableLocales available locales to choose from
  9. * @return Locale the best matching locale, or {@code null} if nothing matches
  10. */
  11. public static Locale getMatchingLocale(String languageRanges, Set<Locale> availableLocales) {
  12. if ((languageRanges == null) || languageRanges.isEmpty()) {
  13. return null;
  14. }
  15. List<Locale> matchingLocales;
  16. try {
  17. matchingLocales = Locale.filter(Locale.LanguageRange.parse(languageRanges), availableLocales);
  18. } catch (IllegalArgumentException e) {
  19. // languageRanges is ill formed
  20. return null;
  21. }
  22. return matchingLocales.isEmpty() ? null : matchingLocales.get(0);
  23. }
  24. }

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

  1. /**
  2. * Returns the best matching locale chosen from a set of available locales for the given language ranges.
  3. *
  4. * @param languageRanges a list of comma-separated language ranges or a list of language ranges in the form of the
  5. * "Accept-Language" header defined in
  6. * <a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC
  7. * 2616</a>
  8. * @param availableLocales available locales to choose from
  9. * @return Locale the best matching locale, or {@code null} if nothing matches
  10. */
  11. public static Locale getMatchingLocale(String languageRanges, Set<Locale> availableLocales) {
  12. if ((languageRanges == null) || languageRanges.isEmpty()) {
  13. return null;
  14. }
  15. List<Locale> matchingLocales;
  16. try {
  17. matchingLocales = Locale.filter(Locale.LanguageRange.parse(languageRanges), availableLocales);
  18. } catch (IllegalArgumentException e) {
  19. // languageRanges is ill formed
  20. return null;
  21. }
  22. return matchingLocales.isEmpty() ? null : matchingLocales.get(0);
  23. }
  24. }

相关文章