Skip to content

Commit 35b95f3

Browse files
committed
Merge pull request #34762 from SeasonPanPan
* pr/34762: Polish "Use removeIf rather than Iterator-based removal" Use removeIf rather than Iterator-based removal Closes gh-34762
2 parents 5a6e7d1 + 4b88293 commit 35b95f3

File tree

2 files changed

+4
-18
lines changed
  • spring-boot-project

2 files changed

+4
-18
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvoker.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,9 +19,7 @@
1919
import java.security.Principal;
2020
import java.time.Duration;
2121
import java.util.Arrays;
22-
import java.util.Iterator;
2322
import java.util.Map;
24-
import java.util.Map.Entry;
2523
import java.util.Objects;
2624

2725
import reactor.core.publisher.Flux;
@@ -109,13 +107,7 @@ private CacheKey getCacheKey(InvocationContext context) {
109107

110108
private void cleanExpiredCachedResponses(long accessTime) {
111109
try {
112-
Iterator<Entry<CacheKey, CachedResponse>> iterator = this.cachedResponses.entrySet().iterator();
113-
while (iterator.hasNext()) {
114-
Entry<CacheKey, CachedResponse> entry = iterator.next();
115-
if (entry.getValue().isStale(accessTime, this.timeToLive)) {
116-
iterator.remove();
117-
}
118-
}
110+
this.cachedResponses.entrySet().removeIf((entry) -> entry.getValue().isStale(accessTime, this.timeToLive));
119111
}
120112
catch (Exception ex) {
121113
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Collections;
2525
import java.util.HashMap;
2626
import java.util.HashSet;
27-
import java.util.Iterator;
2827
import java.util.LinkedHashSet;
2928
import java.util.List;
3029
import java.util.Locale;
@@ -182,13 +181,8 @@ protected final MatchResult getMatchingBeans(ConditionContext context, Spec<?> s
182181
for (String type : spec.getTypes()) {
183182
Collection<String> typeMatches = getBeanNamesForType(classLoader, considerHierarchy, beanFactory, type,
184183
parameterizedContainers);
185-
Iterator<String> iterator = typeMatches.iterator();
186-
while (iterator.hasNext()) {
187-
String match = iterator.next();
188-
if (beansIgnoredByType.contains(match) || ScopedProxyUtils.isScopedTarget(match)) {
189-
iterator.remove();
190-
}
191-
}
184+
typeMatches
185+
.removeIf((match) -> beansIgnoredByType.contains(match) || ScopedProxyUtils.isScopedTarget(match));
192186
if (typeMatches.isEmpty()) {
193187
result.recordUnmatchedType(type);
194188
}

0 commit comments

Comments
 (0)