You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/04/20 13:54:31 UTC

[GitHub] [commons-lang] namannigam commented on a change in pull request #523: Simplify the finding of matching Locales in LocaleUtils using the Streams API.

namannigam commented on a change in pull request #523:
URL: https://github.com/apache/commons-lang/pull/523#discussion_r411396657



##########
File path: src/main/java/org/apache/commons/lang3/LocaleUtils.java
##########
@@ -295,14 +297,13 @@ public static boolean isAvailableLocale(final Locale locale) {
         }
         List<Locale> langs = cLanguagesByCountry.get(countryCode);
         if (langs == null) {
-            langs = new ArrayList<>();
-            final List<Locale> locales = availableLocaleList();
-            for (final Locale locale : locales) {
-                if (countryCode.equals(locale.getCountry()) &&
-                    locale.getVariant().isEmpty()) {
-                    langs.add(locale);
-                }
-            }
+            // Allows Locales to be processed using multiple threads.
+            langs = availableLocaleList().parallelStream()
+                    .filter(locale -> countryCode.equals(locale.getCountry()))
+                    .filter(locale -> locale.getVariant().isEmpty())
+                    .collect(Collectors.toList());
+            // Collectors.toUnmodifiableList() is an alternative, but it is only
+            // available starting with Java 10.
             langs = Collections.unmodifiableList(langs);
             cLanguagesByCountry.putIfAbsent(countryCode, langs);

Review comment:
       curious, could all of this be replaced with any of the `compute..` variants in `Map`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org