Isira-Seneviratne commented on a change in pull request #523:
URL: https://github.com/apache/commons-lang/pull/523#discussion_r411409043
##########
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 does make use of parallelStream(), though, so there should be at
least a decent performance improvement.
----------------------------------------------------------------
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]