diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java index 62b5c43635..26d73e0303 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java @@ -16,7 +16,6 @@ package org.springframework.boot.actuate.cache; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -112,21 +111,19 @@ public class CachesEndpoint { private List getCacheEntries(Predicate cacheNamePredicate, Predicate cacheManagerNamePredicate) { - List entries = new ArrayList<>(); - this.cacheManagers.keySet().stream().filter(cacheManagerNamePredicate) - .forEach((cacheManagerName) -> entries - .addAll(getCacheEntries(cacheManagerName, cacheNamePredicate))); - return entries; + return this.cacheManagers.keySet().stream().filter(cacheManagerNamePredicate) + .flatMap((cacheManagerName) -> getCacheEntries(cacheManagerName, + cacheNamePredicate).stream()) + .collect(Collectors.toList()); } private List getCacheEntries(String cacheManagerName, Predicate cacheNamePredicate) { CacheManager cacheManager = this.cacheManagers.get(cacheManagerName); - List entries = new ArrayList<>(); - cacheManager.getCacheNames().stream().filter(cacheNamePredicate) + return cacheManager.getCacheNames().stream().filter(cacheNamePredicate) .map(cacheManager::getCache).filter(Objects::nonNull) - .forEach((cache) -> entries.add(new CacheEntry(cache, cacheManagerName))); - return entries; + .map((cache) -> new CacheEntry(cache, cacheManagerName)) + .collect(Collectors.toList()); } private CacheEntry extractUniqueCacheEntry(String cache, List entries) {