Use computeIfAbsent in ResourceBundleMessageSource
This commit optimizes code in ResourceBundleMessageSource by using computeIfAbsent instead of putIfAbsent. In addition, the content of some Javadoc has been adjusted. Closes gh-25054
This commit is contained in:
parent
d54b903d28
commit
311b333814
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -183,8 +183,8 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
|
|||
|
||||
|
||||
/**
|
||||
* Return a ResourceBundle for the given basename and code,
|
||||
* fetching already generated MessageFormats from the cache.
|
||||
* Return a ResourceBundle for the given basename and Locale,
|
||||
* fetching already generated ResourceBundle from the cache.
|
||||
* @param basename the basename of the ResourceBundle
|
||||
* @param locale the Locale to find the ResourceBundle for
|
||||
* @return the resulting ResourceBundle, or {@code null} if none
|
||||
|
|
@ -209,11 +209,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
|
|||
try {
|
||||
ResourceBundle bundle = doGetBundle(basename, locale);
|
||||
if (localeMap == null) {
|
||||
localeMap = new ConcurrentHashMap<>();
|
||||
Map<Locale, ResourceBundle> existing = this.cachedResourceBundles.putIfAbsent(basename, localeMap);
|
||||
if (existing != null) {
|
||||
localeMap = existing;
|
||||
}
|
||||
localeMap = this.cachedResourceBundles.computeIfAbsent(basename, bn -> new ConcurrentHashMap<>());
|
||||
}
|
||||
localeMap.put(locale, bundle);
|
||||
return bundle;
|
||||
|
|
|
|||
Loading…
Reference in New Issue