Merge pull request #13487 from izeye:caches-endpoint

* pr/13487:
  Polish CachesEndpoint
pull/13421/merge
Stephane Nicoll 7 years ago
commit da49128e69

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

Loading…
Cancel
Save