Replace use of Collections.unmodifiable*() methods where appropriate

Closes gh-29321
This commit is contained in:
divcon
2022-10-14 12:57:30 +09:00
committed by Sam Brannen
parent 86d45578d9
commit ba136dcf40
11 changed files with 24 additions and 50 deletions

View File

@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.Cache;
@@ -64,13 +65,13 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
synchronized (this.cacheMap) {
this.cacheNames = Collections.emptySet();
this.cacheMap.clear();
Set<String> cacheNames = new LinkedHashSet<>(caches.size());
for (Cache cache : caches) {
String name = cache.getName();
this.cacheMap.put(name, decorateCache(cache));
cacheNames.add(name);
}
this.cacheNames = Collections.unmodifiableSet(cacheNames);
this.cacheNames = caches.stream()
.map(Cache::getName)
.collect(Collectors.toUnmodifiableSet());
}
}

View File

@@ -19,9 +19,7 @@ package org.springframework.format.datetime;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -49,15 +47,10 @@ public class DateFormatter implements Formatter<Date> {
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
private static final Map<ISO, String> ISO_PATTERNS;
static {
Map<ISO, String> formats = new EnumMap<>(ISO.class);
formats.put(ISO.DATE, "yyyy-MM-dd");
formats.put(ISO.TIME, "HH:mm:ss.SSSXXX");
formats.put(ISO.DATE_TIME, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
ISO_PATTERNS = Collections.unmodifiableMap(formats);
}
private static final Map<ISO, String> ISO_PATTERNS = Map.of(
ISO.DATE, "yyyy-MM-dd",
ISO.TIME, "HH:mm:ss.SSSXXX",
ISO.DATE_TIME, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
@Nullable