Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/java/com/github/fge/msgsimple/bundle/MessageBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.IllegalFormatException;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
* A message bundle
Expand Down Expand Up @@ -67,6 +69,9 @@ public final class MessageBundle

final List<MessageSourceProvider> providers
= new ArrayList<MessageSourceProvider>();
private final ConcurrentMap<Locale, ConcurrentMap<String, String>> cache
= new ConcurrentHashMap<>();


/**
* Create a new, empty builder for a bundle
Expand Down Expand Up @@ -109,10 +114,14 @@ public static MessageBundle withSingleSource(final MessageSource source)
* found
* @throws NullPointerException either the key or the locale is null
*/
public String getMessage(final Locale locale, final String key)
{
public String getMessage(final Locale locale, final String key) {
BUNDLE.checkNotNull(key, "query.nullKey");
BUNDLE.checkNotNull(locale, "query.nullLocale");
var localCache = cache.computeIfAbsent(locale, k -> new ConcurrentHashMap<>());
return localCache.computeIfAbsent(key, k -> getMessageImpl(locale, k));
}
private String getMessageImpl(final Locale locale, final String key)
{

String ret;
MessageSource source;
Expand Down