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



##########
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:
       It's also not "simpler", it's just different, without even thinking 
about performance consequences....




----------------------------------------------------------------
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:
[email protected]


Reply via email to