Skip to content

Commit 69bc19e

Browse files
igor-suhorukovphilwebb
authored andcommitted
Use lambdas for map entry iteration where possible
See gh-12626
1 parent 78a94ca commit 69bc19e

File tree

31 files changed

+125
-232
lines changed

31 files changed

+125
-232
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ public ContextConditionEvaluation(ConfigurableApplicationContext context) {
123123
this.negativeMatches = new LinkedHashMap<>();
124124
this.exclusions = report.getExclusions();
125125
this.unconditionalClasses = report.getUnconditionalClasses();
126-
for (Map.Entry<String, ConditionAndOutcomes> entry : report
127-
.getConditionAndOutcomesBySource().entrySet()) {
128-
if (entry.getValue().isFullMatch()) {
129-
add(this.positiveMatches, entry.getKey(), entry.getValue());
126+
report.getConditionAndOutcomesBySource().forEach((key, value) -> {
127+
if (value.isFullMatch()) {
128+
add(this.positiveMatches, key, value);
130129
}
131130
else {
132-
add(this.negativeMatches, entry.getKey(), entry.getValue());
131+
add(this.negativeMatches, key, value);
133132
}
134-
}
133+
});
135134
this.parentId = context.getParent() == null ? null
136135
: context.getParent().getId();
137136
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ protected HealthIndicator createHealthIndicator(Map<String, S> beans) {
4444
}
4545
CompositeHealthIndicator composite = new CompositeHealthIndicator(
4646
this.healthAggregator);
47-
for (Map.Entry<String, S> entry : beans.entrySet()) {
48-
composite.addHealthIndicator(entry.getKey(),
49-
createHealthIndicator(entry.getValue()));
50-
}
47+
beans.forEach((key, value) -> composite.addHealthIndicator(key, createHealthIndicator(value)));
5148
return composite;
5249
}
5350

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ protected ReactiveHealthIndicator createHealthIndicator(Map<String, S> beans) {
4343
}
4444
CompositeReactiveHealthIndicator composite = new CompositeReactiveHealthIndicator(
4545
this.healthAggregator);
46-
for (Map.Entry<String, S> entry : beans.entrySet()) {
47-
composite.addHealthIndicator(entry.getKey(),
48-
createHealthIndicator(entry.getValue()));
49-
}
46+
beans.forEach((key, value) -> composite.addHealthIndicator(key, createHealthIndicator(value)));
5047
return composite;
5148
}
5249

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ private Map<String, DataSource> filterDataSources(
8484
return null;
8585
}
8686
Map<String, DataSource> dataSources = new LinkedHashMap<>();
87-
for (Map.Entry<String, DataSource> entry : candidates.entrySet()) {
88-
if (!(entry.getValue() instanceof AbstractRoutingDataSource)) {
89-
dataSources.put(entry.getKey(), entry.getValue());
87+
candidates.forEach((key, value) -> {
88+
if (!(value instanceof AbstractRoutingDataSource)) {
89+
dataSources.put(key, value);
9090
}
91-
}
91+
});
9292
return dataSources;
9393
}
9494

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,10 @@ private List<PropertySourceEntryDescriptor> toPropertySourceDescriptors(
120120

121121
private PropertySummaryDescriptor getPropertySummaryDescriptor(
122122
Map<String, PropertyValueDescriptor> descriptors) {
123-
for (Map.Entry<String, PropertyValueDescriptor> entry : descriptors.entrySet()) {
124-
if (entry.getValue() != null) {
125-
return new PropertySummaryDescriptor(entry.getKey(),
126-
entry.getValue().getValue());
127-
}
128-
}
129-
return null;
123+
return descriptors.entrySet().stream().
124+
filter((entry) -> entry.getValue() != null).
125+
map((entry) -> new PropertySummaryDescriptor(entry.getKey(), entry.getValue().getValue())).
126+
findFirst().orElse(null);
130127
}
131128

132129
private Map<String, PropertyValueDescriptor> getPropertySourceDescriptors(

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@ public AutoConfigurationClass get(String className) {
142142
public Set<String> getClassesRequestedAfter(String className) {
143143
Set<String> rtn = new LinkedHashSet<>();
144144
rtn.addAll(get(className).getAfter());
145-
for (Map.Entry<String, AutoConfigurationClass> entry : this.classes
146-
.entrySet()) {
147-
if (entry.getValue().getBefore().contains(className)) {
148-
rtn.add(entry.getKey());
145+
this.classes.forEach((key, value) -> {
146+
if (value.getBefore().contains(className)) {
147+
rtn.add(key);
149148
}
150-
}
149+
});
151150
return rtn;
152151
}
153152

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
7474
AnnotationAttributes attributes) {
7575
List<String> candidates = new ArrayList<>();
7676
Map<Class<?>, List<Annotation>> annotations = getAnnotations(metadata);
77-
for (Map.Entry<Class<?>, List<Annotation>> entry : annotations.entrySet()) {
78-
collectCandidateConfigurations(entry.getKey(), entry.getValue(), candidates);
79-
}
77+
annotations.forEach((key, value) -> {
78+
collectCandidateConfigurations(key, value, candidates);
79+
});
8080
return candidates;
8181
}
8282

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ public static String getConfigurationClass(CacheType cacheType) {
5757
}
5858

5959
public static CacheType getType(String configurationClassName) {
60-
for (Map.Entry<CacheType, Class<?>> entry : MAPPINGS.entrySet()) {
61-
if (entry.getValue().getName().equals(configurationClassName)) {
62-
return entry.getKey();
63-
}
64-
}
65-
throw new IllegalStateException(
66-
"Unknown configuration class " + configurationClassName);
60+
return MAPPINGS.entrySet().stream().filter((entry) ->
61+
entry.getValue().getName().equals(configurationClassName)).
62+
map(Map.Entry::getKey).findFirst().
63+
orElseThrow(() -> new IllegalStateException("Unknown configuration class " + configurationClassName));
6764
}
6865

6966
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,8 @@ private Condition getCondition(String conditionClassName) {
159159

160160
public List<ConditionOutcome> getMatchOutcomes() {
161161
List<ConditionOutcome> outcomes = new ArrayList<>();
162-
for (Map.Entry<AnnotationMetadata, List<Condition>> entry : this.memberConditions
163-
.entrySet()) {
164-
AnnotationMetadata metadata = entry.getKey();
165-
List<Condition> conditions = entry.getValue();
166-
outcomes.add(new MemberOutcomes(this.context, metadata, conditions)
167-
.getUltimateOutcome());
168-
}
162+
this.memberConditions.forEach((metadata, conditions) ->
163+
outcomes.add(new MemberOutcomes(this.context, metadata, conditions).getUltimateOutcome()));
169164
return Collections.unmodifiableList(outcomes);
170165
}
171166

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.LinkedHashSet;
2525
import java.util.Map;
2626
import java.util.Set;
27+
import java.util.stream.Collectors;
2728

2829
import org.apache.commons.logging.Log;
2930
import org.apache.commons.logging.LogFactory;
@@ -112,13 +113,9 @@ static BeanTypeRegistry get(ListableBeanFactory beanFactory) {
112113
*/
113114
Set<String> getNamesForType(Class<?> type) {
114115
updateTypesIfNecessary();
115-
Set<String> matches = new LinkedHashSet<>();
116-
for (Map.Entry<String, Class<?>> entry : this.beanTypes.entrySet()) {
117-
if (entry.getValue() != null && type.isAssignableFrom(entry.getValue())) {
118-
matches.add(entry.getKey());
119-
}
120-
}
121-
return matches;
116+
return this.beanTypes.entrySet().stream().filter((entry) -> entry.getValue() != null &&
117+
type.isAssignableFrom(entry.getValue())).
118+
map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new));
122119
}
123120

124121
/**
@@ -132,14 +129,9 @@ Set<String> getNamesForType(Class<?> type) {
132129
*/
133130
Set<String> getNamesForAnnotation(Class<? extends Annotation> annotation) {
134131
updateTypesIfNecessary();
135-
Set<String> matches = new LinkedHashSet<>();
136-
for (Map.Entry<String, Class<?>> entry : this.beanTypes.entrySet()) {
137-
if (entry.getValue() != null && AnnotationUtils
138-
.findAnnotation(entry.getValue(), annotation) != null) {
139-
matches.add(entry.getKey());
140-
}
141-
}
142-
return matches;
132+
return this.beanTypes.entrySet().stream().filter((entry) -> entry.getValue() != null &&
133+
AnnotationUtils.findAnnotation(entry.getValue(), annotation) != null).
134+
map(Map.Entry::getKey).collect(Collectors.toCollection(LinkedHashSet::new));
143135
}
144136

145137
@Override

0 commit comments

Comments
 (0)