This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
commit e86d486f1943014c5bcd52504ecd25b813adc769 Author: Gary Gregory <[email protected]> AuthorDate: Thu Feb 25 11:16:54 2021 -0500 Cleanups. - Inline single use local vars. - Use Java 8 API. - Sort methods. --- .../org/apache/commons/vfs2/util/Messages.java | 28 ++++++++-------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java index 6343095..e226b73 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java @@ -28,13 +28,19 @@ import java.util.concurrent.ConcurrentMap; public final class Messages { private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + /** * Map from message code to MessageFormat object for the message. */ private static final ConcurrentMap<String, MessageFormat> messageMap = new ConcurrentHashMap<>(); private static final ResourceBundle RESOURCES = new CombinedResources("org.apache.commons.vfs2.Resources"); - private Messages() { + /** + * Locates a message by its code. + */ + private static MessageFormat findMessage(final String code) throws MissingResourceException { + // Check if the message is cached + return messageMap.computeIfAbsent(code, k -> new MessageFormat(RESOURCES.getString(k))); } /** @@ -73,27 +79,13 @@ public final class Messages { if (code == null) { return null; } - - final MessageFormat msg = findMessage(code); - return msg.format(params); + return findMessage(code).format(params); } catch (final MissingResourceException mre) { return "Unknown message with code \"" + code + "\"."; } } - /** - * Locates a message by its code. - */ - private static MessageFormat findMessage(final String code) throws MissingResourceException { - // Check if the message is cached - MessageFormat msg = messageMap.get(code); - if (msg != null) { - return msg; - } - - final String msgText = RESOURCES.getString(code); - msg = new MessageFormat(msgText); - messageMap.putIfAbsent(code, msg); - return messageMap.get(code); + private Messages() { + // no instances. } }
