Skip to content

Commit 685babc

Browse files
committed
Polish "Use lambdas for map entry iteration where possible"
Closes gh-12626
1 parent 69bc19e commit 685babc

File tree

27 files changed

+207
-174
lines changed

27 files changed

+207
-174
lines changed

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,21 @@ public ContextConditionEvaluation(ConfigurableApplicationContext context) {
123123
this.negativeMatches = new LinkedHashMap<>();
124124
this.exclusions = report.getExclusions();
125125
this.unconditionalClasses = report.getUnconditionalClasses();
126-
report.getConditionAndOutcomesBySource().forEach((key, value) -> {
127-
if (value.isFullMatch()) {
128-
add(this.positiveMatches, key, value);
129-
}
130-
else {
131-
add(this.negativeMatches, key, value);
132-
}
133-
});
126+
report.getConditionAndOutcomesBySource().forEach(
127+
(source, conditionAndOutcomes) -> add(source, conditionAndOutcomes));
134128
this.parentId = context.getParent() == null ? null
135129
: context.getParent().getId();
136130
}
137131

138-
private void add(Map<String, MessageAndConditions> map, String source,
139-
ConditionAndOutcomes conditionAndOutcomes) {
132+
private void add(String source, ConditionAndOutcomes conditionAndOutcomes) {
140133
String name = ClassUtils.getShortName(source);
141-
map.put(name, new MessageAndConditions(conditionAndOutcomes));
142-
}
143-
144-
private void add(MultiValueMap<String, MessageAndCondition> map, String source,
145-
ConditionAndOutcomes conditionAndOutcomes) {
146-
String name = ClassUtils.getShortName(source);
147-
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
148-
map.add(name, new MessageAndCondition(conditionAndOutcome));
134+
if (conditionAndOutcomes.isFullMatch()) {
135+
conditionAndOutcomes.forEach((conditionAndOutcome) -> this.positiveMatches
136+
.add(name, new MessageAndCondition(conditionAndOutcome)));
137+
}
138+
else {
139+
this.negativeMatches.put(name,
140+
new MessageAndConditions(conditionAndOutcomes));
149141
}
150142
}
151143

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -44,7 +44,8 @@ protected HealthIndicator createHealthIndicator(Map<String, S> beans) {
4444
}
4545
CompositeHealthIndicator composite = new CompositeHealthIndicator(
4646
this.healthAggregator);
47-
beans.forEach((key, value) -> composite.addHealthIndicator(key, createHealthIndicator(value)));
47+
beans.forEach((name, source) -> composite.addHealthIndicator(name,
48+
createHealthIndicator(source)));
4849
return composite;
4950
}
5051

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -43,7 +43,8 @@ protected ReactiveHealthIndicator createHealthIndicator(Map<String, S> beans) {
4343
}
4444
CompositeReactiveHealthIndicator composite = new CompositeReactiveHealthIndicator(
4545
this.healthAggregator);
46-
beans.forEach((key, value) -> composite.addHealthIndicator(key, createHealthIndicator(value)));
46+
beans.forEach((name, source) -> composite.addHealthIndicator(name,
47+
createHealthIndicator(source)));
4748
return composite;
4849
}
4950

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
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -84,9 +84,9 @@ private Map<String, DataSource> filterDataSources(
8484
return null;
8585
}
8686
Map<String, DataSource> dataSources = new LinkedHashMap<>();
87-
candidates.forEach((key, value) -> {
88-
if (!(value instanceof AbstractRoutingDataSource)) {
89-
dataSources.put(key, value);
87+
candidates.forEach((name, dataSource) -> {
88+
if (!(dataSource instanceof AbstractRoutingDataSource)) {
89+
dataSources.put(name, dataSource);
9090
}
9191
});
9292
return dataSources;

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

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

121121
private PropertySummaryDescriptor getPropertySummaryDescriptor(
122122
Map<String, PropertyValueDescriptor> descriptors) {
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);
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;
127130
}
128131

129132
private Map<String, PropertyValueDescriptor> getPropertySourceDescriptors(

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ public AutoConfigurationClass get(String className) {
140140
}
141141

142142
public Set<String> getClassesRequestedAfter(String className) {
143-
Set<String> rtn = new LinkedHashSet<>();
144-
rtn.addAll(get(className).getAfter());
145-
this.classes.forEach((key, value) -> {
146-
if (value.getBefore().contains(className)) {
147-
rtn.add(key);
143+
Set<String> classesRequestedAfter = new LinkedHashSet<>();
144+
classesRequestedAfter.addAll(get(className).getAfter());
145+
this.classes.forEach((name, autoConfigurationClass) -> {
146+
if (autoConfigurationClass.getBefore().contains(className)) {
147+
classesRequestedAfter.add(name);
148148
}
149149
});
150-
return rtn;
150+
return classesRequestedAfter;
151151
}
152152

153153
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -74,9 +74,8 @@ protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
7474
AnnotationAttributes attributes) {
7575
List<String> candidates = new ArrayList<>();
7676
Map<Class<?>, List<Annotation>> annotations = getAnnotations(metadata);
77-
annotations.forEach((key, value) -> {
78-
collectCandidateConfigurations(key, value, candidates);
79-
});
77+
annotations.forEach((source, sourceAnnotations) -> collectCandidateConfigurations(
78+
source, sourceAnnotations, candidates));
8079
return candidates;
8180
}
8281

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

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

5959
public static CacheType getType(String 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));
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);
6467
}
6568

6669
}

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

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

160160
public List<ConditionOutcome> getMatchOutcomes() {
161161
List<ConditionOutcome> outcomes = new ArrayList<>();
162-
this.memberConditions.forEach((metadata, conditions) ->
163-
outcomes.add(new MemberOutcomes(this.context, metadata, conditions).getUltimateOutcome()));
162+
this.memberConditions.forEach((metadata, conditions) -> outcomes
163+
.add(new MemberOutcomes(this.context, metadata, conditions)
164+
.getUltimateOutcome()));
164165
return Collections.unmodifiableList(outcomes);
165166
}
166167

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ static BeanTypeRegistry get(ListableBeanFactory beanFactory) {
113113
*/
114114
Set<String> getNamesForType(Class<?> type) {
115115
updateTypesIfNecessary();
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));
116+
return this.beanTypes.entrySet().stream()
117+
.filter((entry) -> entry.getValue() != null
118+
&& type.isAssignableFrom(entry.getValue()))
119+
.map(Map.Entry::getKey)
120+
.collect(Collectors.toCollection(LinkedHashSet::new));
119121
}
120122

121123
/**
@@ -129,9 +131,11 @@ Set<String> getNamesForType(Class<?> type) {
129131
*/
130132
Set<String> getNamesForAnnotation(Class<? extends Annotation> annotation) {
131133
updateTypesIfNecessary();
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));
134+
return this.beanTypes.entrySet().stream()
135+
.filter((entry) -> entry.getValue() != null && AnnotationUtils
136+
.findAnnotation(entry.getValue(), annotation) != null)
137+
.map(Map.Entry::getKey)
138+
.collect(Collectors.toCollection(LinkedHashSet::new));
135139
}
136140

137141
@Override

0 commit comments

Comments
 (0)