From 9698dbc23284811c0134055a023e3db73a5d7569 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 6 Feb 2024 09:13:09 +0100 Subject: [PATCH] Add javadoc and rename merge method to mergeProperties See gh-32118 --- .../AbstractResourceBasedMessageSource.java | 3 ++- ...ReloadableResourceBundleMessageSource.java | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java index 37ffa85e40fd..0d633af00716 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -110,6 +110,7 @@ public void addBasenames(String... basenames) { * in the order of registration. *

Calling code may introspect this set as well as add or remove entries. * @since 4.3 + * @see #setBasenames * @see #addBasenames */ public Set getBasenameSet() { diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index 1f5154ffd5ba..4d596fddb526 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -250,16 +250,15 @@ protected MessageFormat resolveCode(String code, Locale locale) { *

Only used when caching resource bundle contents forever, i.e. * with cacheSeconds < 0. Therefore, merged properties are always * cached forever. + * @see #collectPropertiesToMerge + * @see #mergeProperties */ protected PropertiesHolder getMergedProperties(Locale locale) { PropertiesHolder mergedHolder = this.cachedMergedProperties.get(locale); if (mergedHolder != null) { return mergedHolder; } - - List holders = collectPropertiesToMerge(locale); - - mergedHolder = merge(holders); + mergedHolder = mergeProperties(collectPropertiesToMerge(locale)); PropertiesHolder existing = this.cachedMergedProperties.putIfAbsent(locale, mergedHolder); if (existing != null) { mergedHolder = existing; @@ -267,6 +266,15 @@ protected PropertiesHolder getMergedProperties(Locale locale) { return mergedHolder; } + /** + * Determine the properties to merge based on the specified basenames. + * @param locale the locale + * @return the list of properties holders + * @since 6.1.4 + * @see #getBasenameSet() + * @see #calculateAllFilenames + * @see #mergeProperties + */ protected List collectPropertiesToMerge(Locale locale) { String[] basenames = StringUtils.toStringArray(getBasenameSet()); List holders = new ArrayList<>(basenames.length); @@ -283,7 +291,16 @@ protected List collectPropertiesToMerge(Locale locale) { return holders; } - protected PropertiesHolder merge(List holders) { + /** + * Merge the given properties holders into a single holder. + * @param holders the list of properties holders + * @return a single merged holder + * @since 6.1.4 + * @see #newProperties() + * @see #getMergedProperties + * @see #collectPropertiesToMerge + */ + protected PropertiesHolder mergeProperties(List holders) { Properties mergedProps = newProperties(); long latestTimestamp = -1; for (PropertiesHolder holder : holders) {