Merge pull request #12626 from igor-suhorukov

* pr/12626:
  Polish "Use lambdas for map entry iteration where possible"
  Use lambdas for map entry iteration where possible
pull/12767/merge
Phillip Webb 7 years ago
commit 236b1bc4b6

@ -123,30 +123,21 @@ public class ConditionsReportEndpoint {
this.negativeMatches = new LinkedHashMap<>();
this.exclusions = report.getExclusions();
this.unconditionalClasses = report.getUnconditionalClasses();
for (Map.Entry<String, ConditionAndOutcomes> entry : report
.getConditionAndOutcomesBySource().entrySet()) {
if (entry.getValue().isFullMatch()) {
add(this.positiveMatches, entry.getKey(), entry.getValue());
}
else {
add(this.negativeMatches, entry.getKey(), entry.getValue());
}
}
report.getConditionAndOutcomesBySource().forEach(
(source, conditionAndOutcomes) -> add(source, conditionAndOutcomes));
this.parentId = context.getParent() == null ? null
: context.getParent().getId();
}
private void add(Map<String, MessageAndConditions> map, String source,
ConditionAndOutcomes conditionAndOutcomes) {
String name = ClassUtils.getShortName(source);
map.put(name, new MessageAndConditions(conditionAndOutcomes));
}
private void add(MultiValueMap<String, MessageAndCondition> map, String source,
ConditionAndOutcomes conditionAndOutcomes) {
private void add(String source, ConditionAndOutcomes conditionAndOutcomes) {
String name = ClassUtils.getShortName(source);
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
map.add(name, new MessageAndCondition(conditionAndOutcome));
if (conditionAndOutcomes.isFullMatch()) {
conditionAndOutcomes.forEach((conditionAndOutcome) -> this.positiveMatches
.add(name, new MessageAndCondition(conditionAndOutcome)));
}
else {
this.negativeMatches.put(name,
new MessageAndConditions(conditionAndOutcomes));
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,10 +44,8 @@ public abstract class CompositeHealthIndicatorConfiguration<H extends HealthIndi
}
CompositeHealthIndicator composite = new CompositeHealthIndicator(
this.healthAggregator);
for (Map.Entry<String, S> entry : beans.entrySet()) {
composite.addHealthIndicator(entry.getKey(),
createHealthIndicator(entry.getValue()));
}
beans.forEach((name, source) -> composite.addHealthIndicator(name,
createHealthIndicator(source)));
return composite;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,10 +43,8 @@ public abstract class CompositeReactiveHealthIndicatorConfiguration<H extends Re
}
CompositeReactiveHealthIndicator composite = new CompositeReactiveHealthIndicator(
this.healthAggregator);
for (Map.Entry<String, S> entry : beans.entrySet()) {
composite.addHealthIndicator(entry.getKey(),
createHealthIndicator(entry.getValue()));
}
beans.forEach((name, source) -> composite.addHealthIndicator(name,
createHealthIndicator(source)));
return composite;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -84,11 +84,11 @@ public class DataSourceHealthIndicatorAutoConfiguration extends
return null;
}
Map<String, DataSource> dataSources = new LinkedHashMap<>();
for (Map.Entry<String, DataSource> entry : candidates.entrySet()) {
if (!(entry.getValue() instanceof AbstractRoutingDataSource)) {
dataSources.put(entry.getKey(), entry.getValue());
candidates.forEach((name, dataSource) -> {
if (!(dataSource instanceof AbstractRoutingDataSource)) {
dataSources.put(name, dataSource);
}
}
});
return dataSources;
}

@ -140,15 +140,14 @@ class AutoConfigurationSorter {
}
public Set<String> getClassesRequestedAfter(String className) {
Set<String> rtn = new LinkedHashSet<>();
rtn.addAll(get(className).getAfter());
for (Map.Entry<String, AutoConfigurationClass> entry : this.classes
.entrySet()) {
if (entry.getValue().getBefore().contains(className)) {
rtn.add(entry.getKey());
Set<String> classesRequestedAfter = new LinkedHashSet<>();
classesRequestedAfter.addAll(get(className).getAfter());
this.classes.forEach((name, autoConfigurationClass) -> {
if (autoConfigurationClass.getBefore().contains(className)) {
classesRequestedAfter.add(name);
}
}
return rtn;
});
return classesRequestedAfter;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -74,9 +74,8 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec
AnnotationAttributes attributes) {
List<String> candidates = new ArrayList<>();
Map<Class<?>, List<Annotation>> annotations = getAnnotations(metadata);
for (Map.Entry<Class<?>, List<Annotation>> entry : annotations.entrySet()) {
collectCandidateConfigurations(entry.getKey(), entry.getValue(), candidates);
}
annotations.forEach((source, sourceAnnotations) -> collectCandidateConfigurations(
source, sourceAnnotations, candidates));
return candidates;
}

@ -159,13 +159,9 @@ public abstract class AbstractNestedCondition extends SpringBootCondition
public List<ConditionOutcome> getMatchOutcomes() {
List<ConditionOutcome> outcomes = new ArrayList<>();
for (Map.Entry<AnnotationMetadata, List<Condition>> entry : this.memberConditions
.entrySet()) {
AnnotationMetadata metadata = entry.getKey();
List<Condition> conditions = entry.getValue();
outcomes.add(new MemberOutcomes(this.context, metadata, conditions)
.getUltimateOutcome());
}
this.memberConditions.forEach((metadata, conditions) -> outcomes
.add(new MemberOutcomes(this.context, metadata, conditions)
.getUltimateOutcome()));
return Collections.unmodifiableList(outcomes);
}

@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -112,13 +113,11 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
*/
Set<String> getNamesForType(Class<?> type) {
updateTypesIfNecessary();
Set<String> matches = new LinkedHashSet<>();
for (Map.Entry<String, Class<?>> entry : this.beanTypes.entrySet()) {
if (entry.getValue() != null && type.isAssignableFrom(entry.getValue())) {
matches.add(entry.getKey());
}
}
return matches;
return this.beanTypes.entrySet().stream()
.filter((entry) -> entry.getValue() != null
&& type.isAssignableFrom(entry.getValue()))
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
/**
@ -132,14 +131,11 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
*/
Set<String> getNamesForAnnotation(Class<? extends Annotation> annotation) {
updateTypesIfNecessary();
Set<String> matches = new LinkedHashSet<>();
for (Map.Entry<String, Class<?>> entry : this.beanTypes.entrySet()) {
if (entry.getValue() != null && AnnotationUtils
.findAnnotation(entry.getValue(), annotation) != null) {
matches.add(entry.getKey());
}
}
return matches;
return this.beanTypes.entrySet().stream()
.filter((entry) -> entry.getValue() != null && AnnotationUtils
.findAnnotation(entry.getValue(), annotation) != null)
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
@Override

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,7 +24,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
@ -112,12 +111,11 @@ public final class ConditionEvaluationReport {
*/
public Map<String, ConditionAndOutcomes> getConditionAndOutcomesBySource() {
if (!this.addedAncestorOutcomes) {
for (Map.Entry<String, ConditionAndOutcomes> entry : this.outcomes
.entrySet()) {
if (!entry.getValue().isFullMatch()) {
addNoMatchOutcomeToAncestors(entry.getKey());
this.outcomes.forEach((source, sourceOutcomes) -> {
if (!sourceOutcomes.isFullMatch()) {
addNoMatchOutcomeToAncestors(source);
}
}
});
this.addedAncestorOutcomes = true;
}
return Collections.unmodifiableMap(this.outcomes);
@ -125,13 +123,13 @@ public final class ConditionEvaluationReport {
private void addNoMatchOutcomeToAncestors(String source) {
String prefix = source + "$";
for (Entry<String, ConditionAndOutcomes> entry : this.outcomes.entrySet()) {
if (entry.getKey().startsWith(prefix)) {
this.outcomes.forEach((candidateSource, sourceOutcomes) -> {
if (candidateSource.startsWith(prefix)) {
ConditionOutcome outcome = ConditionOutcome.noMatch(ConditionMessage
.forCondition("Ancestor " + source).because("did not match"));
entry.getValue().add(ANCESTOR_CONDITION, outcome);
sourceOutcomes.add(ANCESTOR_CONDITION, outcome);
}
}
});
}
/**
@ -190,16 +188,16 @@ public final class ConditionEvaluationReport {
public ConditionEvaluationReport getDelta(ConditionEvaluationReport previousReport) {
ConditionEvaluationReport delta = new ConditionEvaluationReport();
for (Entry<String, ConditionAndOutcomes> entry : this.outcomes.entrySet()) {
ConditionAndOutcomes previous = previousReport.outcomes.get(entry.getKey());
this.outcomes.forEach((source, sourceOutcomes) -> {
ConditionAndOutcomes previous = previousReport.outcomes.get(source);
if (previous == null
|| previous.isFullMatch() != entry.getValue().isFullMatch()) {
entry.getValue()
.forEach((conditionAndOutcome) -> delta.recordConditionEvaluation(
entry.getKey(), conditionAndOutcome.getCondition(),
|| previous.isFullMatch() != sourceOutcomes.isFullMatch()) {
sourceOutcomes.forEach(
(conditionAndOutcome) -> delta.recordConditionEvaluation(source,
conditionAndOutcome.getCondition(),
conditionAndOutcome.getOutcome()));
}
}
});
List<String> newExclusions = new ArrayList<>(this.exclusions);
newExclusions.removeAll(previousReport.getExclusions());
delta.recordExclusions(newExclusions);

@ -166,18 +166,17 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
private void appendMessageForMatches(StringBuilder reason,
Map<String, Collection<String>> matches, String description) {
if (!matches.isEmpty()) {
for (Map.Entry<String, Collection<String>> match : matches.entrySet()) {
matches.forEach((key, value) -> {
if (reason.length() > 0) {
reason.append(" and ");
}
reason.append("found beans ");
reason.append(description);
reason.append(" '");
reason.append(match.getKey());
reason.append(key);
reason.append("' ");
reason.append(
StringUtils.collectionToDelimitedString(match.getValue(), ", "));
}
reason.append(StringUtils.collectionToDelimitedString(value, ", "));
});
}
}

@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style;
import org.springframework.context.annotation.Condition;
@ -69,8 +68,8 @@ class OnPropertyCondition extends SpringBootCondition {
private List<AnnotationAttributes> annotationAttributesFromMultiValueMap(
MultiValueMap<String, Object> multiValueMap) {
List<Map<String, Object>> maps = new ArrayList<>();
for (Entry<String, List<Object>> entry : multiValueMap.entrySet()) {
for (int i = 0; i < entry.getValue().size(); i++) {
multiValueMap.forEach((key, value) -> {
for (int i = 0; i < value.size(); i++) {
Map<String, Object> map;
if (i < maps.size()) {
map = maps.get(i);
@ -79,9 +78,9 @@ class OnPropertyCondition extends SpringBootCondition {
map = new HashMap<>();
maps.add(map);
}
map.put(entry.getKey(), entry.getValue().get(i));
map.put(key, value.get(i));
}
}
});
List<AnnotationAttributes> annotationAttributes = new ArrayList<>(maps.size());
for (Map<String, Object> map : maps) {
annotationAttributes.add(AnnotationAttributes.fromMap(map));

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -124,19 +124,23 @@ class NoSuchBeanDefinitionFailureAnalyzer
private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause,
List<AutoConfigurationResult> results) {
for (Map.Entry<String, ConditionAndOutcomes> entry : this.report
.getConditionAndOutcomesBySource().entrySet()) {
Source source = new Source(entry.getKey());
ConditionAndOutcomes conditionAndOutcomes = entry.getValue();
if (!conditionAndOutcomes.isFullMatch()) {
BeanMethods methods = new BeanMethods(source, cause);
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
if (!conditionAndOutcome.getOutcome().isMatch()) {
for (MethodMetadata method : methods) {
results.add(new AutoConfigurationResult(method,
conditionAndOutcome.getOutcome(), source.isMethod()));
}
}
this.report.getConditionAndOutcomesBySource().forEach(
(source, sourceOutcomes) -> collectReportedConditionOutcomes(cause,
new Source(source), sourceOutcomes, results));
}
private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause,
Source source, ConditionAndOutcomes sourceOutcomes,
List<AutoConfigurationResult> results) {
if (sourceOutcomes.isFullMatch()) {
return;
}
BeanMethods methods = new BeanMethods(source, cause);
for (ConditionAndOutcome conditionAndOutcome : sourceOutcomes) {
if (!conditionAndOutcome.getOutcome().isMatch()) {
for (MethodMetadata method : methods) {
results.add(new AutoConfigurationResult(method,
conditionAndOutcome.getOutcome(), source.isMethod()));
}
}
}

@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jersey;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Map.Entry;
import javax.annotation.PostConstruct;
import javax.servlet.DispatcherType;
@ -181,9 +180,7 @@ public class JerseyAutoConfiguration implements ServletContextAware {
}
private void addInitParameters(DynamicRegistrationBean<?> registration) {
for (Entry<String, String> entry : this.jersey.getInit().entrySet()) {
registration.addInitParameter(entry.getKey(), entry.getValue());
}
this.jersey.getInit().forEach(registration::addInitParameter);
}
private static String findApplicationPath(ApplicationPath annotation) {

@ -22,6 +22,7 @@ import java.util.Map;
import org.springframework.boot.WebApplicationType;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* Mappings between {@link StoreType} and {@code @Configuration}.
@ -31,69 +32,70 @@ import org.springframework.util.Assert;
*/
final class SessionStoreMappings {
private static final Map<StoreType, Map<WebApplicationType, Class<?>>> MAPPINGS;
private static final Map<StoreType, Configurations> MAPPINGS;
static {
Map<StoreType, Map<WebApplicationType, Class<?>>> mappings = new EnumMap<>(
StoreType.class);
mappings.put(StoreType.REDIS, createMapping(RedisSessionConfiguration.class,
Map<StoreType, Configurations> mappings = new EnumMap<>(StoreType.class);
mappings.put(StoreType.REDIS, new Configurations(RedisSessionConfiguration.class,
RedisReactiveSessionConfiguration.class));
mappings.put(StoreType.MONGODB, createMapping(MongoSessionConfiguration.class,
MongoReactiveSessionConfiguration.class));
mappings.put(StoreType.JDBC, createMapping(JdbcSessionConfiguration.class));
mappings.put(StoreType.MONGODB,
new Configurations(MongoSessionConfiguration.class,
MongoReactiveSessionConfiguration.class));
mappings.put(StoreType.JDBC,
new Configurations(JdbcSessionConfiguration.class, null));
mappings.put(StoreType.HAZELCAST,
createMapping(HazelcastSessionConfiguration.class));
mappings.put(StoreType.NONE, createMapping(NoOpSessionConfiguration.class,
new Configurations(HazelcastSessionConfiguration.class, null));
mappings.put(StoreType.NONE, new Configurations(NoOpSessionConfiguration.class,
NoOpReactiveSessionConfiguration.class));
MAPPINGS = Collections.unmodifiableMap(mappings);
}
static Map<WebApplicationType, Class<?>> createMapping(
Class<?> servletConfiguration) {
return createMapping(servletConfiguration, null);
private SessionStoreMappings() {
}
static Map<WebApplicationType, Class<?>> createMapping(Class<?> servletConfiguration,
Class<?> reactiveConfiguration) {
Map<WebApplicationType, Class<?>> mapping = new EnumMap<>(
WebApplicationType.class);
mapping.put(WebApplicationType.SERVLET, servletConfiguration);
if (reactiveConfiguration != null) {
mapping.put(WebApplicationType.REACTIVE, reactiveConfiguration);
}
return mapping;
public static String getConfigurationClass(WebApplicationType webApplicationType,
StoreType sessionStoreType) {
Configurations configurations = MAPPINGS.get(sessionStoreType);
Assert.state(configurations != null,
() -> "Unknown session store type " + sessionStoreType);
return configurations.getConfiguration(webApplicationType);
}
private SessionStoreMappings() {
public static StoreType getType(WebApplicationType webApplicationType,
String configurationClass) {
return MAPPINGS.entrySet().stream()
.filter((entry) -> ObjectUtils.nullSafeEquals(configurationClass,
entry.getValue().getConfiguration(webApplicationType)))
.map(Map.Entry::getKey).findFirst()
.orElseThrow(() -> new IllegalStateException(
"Unknown configuration class " + configurationClass));
}
static String getConfigurationClass(WebApplicationType webApplicationType,
StoreType sessionStoreType) {
Map<WebApplicationType, Class<?>> configurationClasses = MAPPINGS
.get(sessionStoreType);
Assert.state(configurationClasses != null,
() -> "Unknown session store type " + sessionStoreType);
Class<?> configurationClass = configurationClasses.get(webApplicationType);
if (configurationClass == null) {
return null;
private static class Configurations {
private final Class<?> servletConfiguration;
private final Class<?> reactiveConfiguration;
Configurations(Class<?> servletConfiguration, Class<?> reactiveConfiguration) {
this.servletConfiguration = servletConfiguration;
this.reactiveConfiguration = reactiveConfiguration;
}
return configurationClass.getName();
}
static StoreType getType(WebApplicationType webApplicationType,
String configurationClassName) {
for (Map.Entry<StoreType, Map<WebApplicationType, Class<?>>> storeEntry : MAPPINGS
.entrySet()) {
for (Map.Entry<WebApplicationType, Class<?>> entry : storeEntry.getValue()
.entrySet()) {
if (entry.getKey() == webApplicationType
&& entry.getValue().getName().equals(configurationClassName)) {
return storeEntry.getKey();
}
public String getConfiguration(WebApplicationType webApplicationType) {
switch (webApplicationType) {
case SERVLET:
return getName(this.servletConfiguration);
case REACTIVE:
return getName(this.reactiveConfiguration);
}
return null;
}
private String getName(Class<?> configuration) {
return (configuration == null ? null : configuration.getName());
}
throw new IllegalStateException(
"Unknown configuration class " + configurationClassName);
}
}

@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import javax.servlet.Servlet;
@ -236,9 +235,7 @@ public class WebMvcAutoConfiguration {
}
Map<String, MediaType> mediaTypes = this.mvcProperties.getContentnegotiation()
.getMediaTypes();
for (Entry<String, MediaType> mediaType : mediaTypes.entrySet()) {
configurer.mediaType(mediaType.getKey(), mediaType.getValue());
}
mediaTypes.forEach(configurer::mediaType);
}
@Bean

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.webservices;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@ -83,9 +82,7 @@ public class WebServicesAutoConfiguration {
servlet, urlMapping);
WebServicesProperties.Servlet servletProperties = this.properties.getServlet();
registration.setLoadOnStartup(servletProperties.getLoadOnStartup());
for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) {
registration.addInitParameter(entry.getKey(), entry.getValue());
}
servletProperties.getInit().forEach(registration::addInitParameter);
return registration;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -423,14 +422,8 @@ class ProjectGenerationRequest {
private static void filter(Map<String, ProjectType> projects, String tag,
String tagValue) {
for (Iterator<Map.Entry<String, ProjectType>> it = projects.entrySet()
.iterator(); it.hasNext();) {
Map.Entry<String, ProjectType> entry = it.next();
String value = entry.getValue().getTags().get(tag);
if (!tagValue.equals(value)) {
it.remove();
}
}
projects.entrySet().removeIf(
(entry) -> !tagValue.equals(entry.getValue().getTags().get(tag)));
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.boot.cli.compiler;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.codehaus.groovy.ast.ASTNode;
@ -68,14 +67,10 @@ public abstract class AnnotatedNodeASTTransformation implements ASTTransformatio
for (ImportNode importNode : module.getStarImports()) {
visitAnnotatedNode(importNode, annotationNodes);
}
for (Map.Entry<String, ImportNode> entry : module.getStaticImports()
.entrySet()) {
visitAnnotatedNode(entry.getValue(), annotationNodes);
}
for (Map.Entry<String, ImportNode> entry : module.getStaticStarImports()
.entrySet()) {
visitAnnotatedNode(entry.getValue(), annotationNodes);
}
module.getStaticImports().forEach((name,
importNode) -> visitAnnotatedNode(importNode, annotationNodes));
module.getStaticStarImports().forEach((name,
importNode) -> visitAnnotatedNode(importNode, annotationNodes));
for (ClassNode classNode : module.getClasses()) {
visitAnnotatedNode(classNode, annotationNodes);
classNode.visitContents(classVisitor);

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -63,13 +63,13 @@ public class DevToolsSettings {
private Map<String, Pattern> getPatterns(Map<?, ?> properties, String prefix) {
Map<String, Pattern> patterns = new LinkedHashMap<>();
for (Map.Entry<?, ?> entry : properties.entrySet()) {
String name = String.valueOf(entry.getKey());
properties.forEach((key, value) -> {
String name = String.valueOf(key);
if (name.startsWith(prefix)) {
Pattern pattern = Pattern.compile((String) entry.getValue());
Pattern pattern = Pattern.compile((String) value);
patterns.put(name, pattern);
}
}
});
return patterns;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,13 +18,15 @@ package org.springframework.boot.autoconfigureprocessor;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
@ -156,25 +158,25 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
return result.toString();
}
@SuppressWarnings("unchecked")
private List<Object> getValues(AnnotationMirror annotation) {
List<Object> result = new ArrayList<>();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation
.getElementValues().entrySet()) {
String attributeName = entry.getKey().getSimpleName().toString();
if ("name".equals(attributeName) || "value".equals(attributeName)) {
Object value = entry.getValue().getValue();
if (value instanceof List) {
for (AnnotationValue annotationValue : (List<AnnotationValue>) value) {
result.add(processValue(annotationValue.getValue()));
}
}
else {
result.add(processValue(value));
}
}
return annotation.getElementValues().entrySet().stream()
.filter(this::isNameOrValueAttribute).flatMap(this::getValues)
.collect(Collectors.toList());
}
private boolean isNameOrValueAttribute(Entry<? extends ExecutableElement, ?> entry) {
String attributeName = entry.getKey().getSimpleName().toString();
return "name".equals(attributeName) || "value".equals(attributeName);
}
@SuppressWarnings("unchecked")
private Stream<Object> getValues(Entry<?, ? extends AnnotationValue> entry) {
Object value = entry.getValue().getValue();
if (value instanceof List) {
return ((List<AnnotationValue>) value).stream()
.map((annotation) -> processValue(annotation.getValue()));
}
return result;
return Stream.of(processValue(value));
}
private Object processValue(Object value) {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -93,17 +93,11 @@ public class SimpleConfigurationMetadataRepository
}
else {
// Merge properties
for (Map.Entry<String, ConfigurationMetadataProperty> entry : group
.getProperties().entrySet()) {
putIfAbsent(existingGroup.getProperties(), entry.getKey(),
entry.getValue());
}
group.getProperties().forEach((name, value) -> putIfAbsent(
existingGroup.getProperties(), name, value));
// Merge sources
for (Map.Entry<String, ConfigurationMetadataSource> entry : group
.getSources().entrySet()) {
putIfAbsent(existingGroup.getSources(), entry.getKey(),
entry.getValue());
}
group.getSources().forEach((name,
value) -> putIfAbsent(existingGroup.getSources(), name, value));
}
}

@ -36,7 +36,6 @@ import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
@ -282,10 +281,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
private void processSimpleTypes(String prefix, TypeElement element,
ExecutableElement source, TypeElementMembers members,
Map<String, Object> fieldValues) {
for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters()
.entrySet()) {
String name = entry.getKey();
ExecutableElement getter = entry.getValue();
members.getPublicGetters().forEach((name, getter) -> {
TypeMirror returnType = getter.getReturnType();
ExecutableElement setter = members.getPublicSetter(name, returnType);
VariableElement field = members.getFields().get(name);
@ -305,7 +301,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
dataType, sourceType, null, description, defaultValue,
(deprecated ? getItemDeprecation(getter) : null)));
}
}
});
}
private ItemDeprecation getItemDeprecation(ExecutableElement getter) {
@ -325,11 +321,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
private void processSimpleLombokTypes(String prefix, TypeElement element,
ExecutableElement source, TypeElementMembers members,
Map<String, Object> fieldValues) {
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
String name = entry.getKey();
VariableElement field = entry.getValue();
members.getFields().forEach((name, field) -> {
if (!isLombokField(field, element)) {
continue;
return;
}
TypeMirror returnType = field.asType();
Element returnTypeElement = this.processingEnv.getTypeUtils()
@ -348,32 +342,27 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
dataType, sourceType, null, description, defaultValue,
(deprecated ? new ItemDeprecation() : null)));
}
}
});
}
private void processNestedTypes(String prefix, TypeElement element,
ExecutableElement source, TypeElementMembers members) {
for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters()
.entrySet()) {
String name = entry.getKey();
ExecutableElement getter = entry.getValue();
members.getPublicGetters().forEach((name, getter) -> {
VariableElement field = members.getFields().get(name);
processNestedType(prefix, element, source, name, getter, field,
getter.getReturnType());
}
});
}
private void processNestedLombokTypes(String prefix, TypeElement element,
ExecutableElement source, TypeElementMembers members) {
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
String name = entry.getKey();
VariableElement field = entry.getValue();
members.getFields().forEach((name, field) -> {
if (isLombokField(field, element)) {
ExecutableElement getter = members.getPublicGetter(name, field.asType());
processNestedType(prefix, element, source, name, getter, field,
field.asType());
}
}
});
}
private boolean isLombokField(VariableElement field, TypeElement element) {
@ -544,11 +533,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
private Map<String, Object> getAnnotationElementValues(AnnotationMirror annotation) {
Map<String, Object> values = new LinkedHashMap<>();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation
.getElementValues().entrySet()) {
values.put(entry.getKey().getSimpleName().toString(),
entry.getValue().getValue());
}
annotation.getElementValues().forEach((name, value) -> values
.put(name.getSimpleName().toString(), value.getValue()));
return values;
}

@ -78,13 +78,11 @@ class TypeElementMembers {
processField(field);
}
try {
Map<String, Object> fieldValues = this.fieldValuesParser
.getFieldValues(element);
for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
if (!this.fieldValues.containsKey(entry.getKey())) {
this.fieldValues.put(entry.getKey(), entry.getValue());
this.fieldValuesParser.getFieldValues(element).forEach((name, value) -> {
if (!this.fieldValues.containsKey(name)) {
this.fieldValues.put(name, value);
}
}
});
}
catch (Exception ex) {
// continue

@ -62,9 +62,8 @@ class TypeUtils {
static {
Map<String, TypeKind> primitives = new HashMap<>();
for (Map.Entry<TypeKind, Class<?>> entry : PRIMITIVE_WRAPPERS.entrySet()) {
primitives.put(entry.getValue().getName(), entry.getKey());
}
PRIMITIVE_WRAPPERS.forEach(
(kind, wrapperClass) -> primitives.put(wrapperClass.getName(), kind));
WRAPPER_TO_PRIMITIVE = primitives;
}

@ -20,7 +20,6 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.gradle.api.Action;
import org.gradle.api.Project;
@ -110,9 +109,7 @@ public class BuildInfo extends ConventionTask {
private Map<String, String> coerceToStringValues(Map<String, Object> input) {
Map<String, String> output = new HashMap<>();
for (Entry<String, Object> entry : input.entrySet()) {
output.put(entry.getKey(), entry.getValue().toString());
}
input.forEach((key, value) -> output.put(key, value.toString()));
return output;
}

@ -22,7 +22,6 @@ import java.io.IOException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
/**
@ -79,10 +78,8 @@ public final class BuildPropertiesWriter {
DateTimeFormatter.ISO_INSTANT.format(project.getTime()));
}
if (project.getAdditionalProperties() != null) {
for (Map.Entry<String, String> entry : project.getAdditionalProperties()
.entrySet()) {
properties.put("build." + entry.getKey(), entry.getValue());
}
project.getAdditionalProperties()
.forEach((name, value) -> properties.put("build." + name, value));
}
return properties;
}
@ -118,11 +115,11 @@ public final class BuildPropertiesWriter {
private static void validateAdditionalProperties(
Map<String, String> additionalProperties) {
if (additionalProperties != null) {
for (Entry<String, String> property : additionalProperties.entrySet()) {
if (property.getValue() == null) {
throw new NullAdditionalPropertyValueException(property.getKey());
additionalProperties.forEach((name, value) -> {
if (value == null) {
throw new NullAdditionalPropertyValueException(name);
}
}
});
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.boot.maven;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@ -59,18 +58,17 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
}
@Override
public void processResource(String resource, InputStream is,
public void processResource(String resource, InputStream inputStream,
List<Relocator> relocators) throws IOException {
Properties properties = new Properties();
properties.load(is);
is.close();
for (Entry<Object, Object> entry : properties.entrySet()) {
String name = (String) entry.getKey();
String value = (String) entry.getValue();
String existing = this.data.getProperty(name);
this.data.setProperty(name,
existing == null ? value : existing + "," + value);
}
properties.load(inputStream);
inputStream.close();
properties.forEach((name, value) -> process((String) name, (String) value));
}
private void process(String name, String value) {
String existing = this.data.getProperty(name);
this.data.setProperty(name, (existing == null ? value : existing + "," + value));
}
@Override

@ -140,13 +140,11 @@ public final class Verify {
}
private ZipEntry getEntryStartingWith(String entryName) {
for (Map.Entry<String, ZipEntry> entry : this.content.entrySet()) {
if (entry.getKey().startsWith(entryName)) {
return entry.getValue();
}
}
throw new IllegalStateException(
"Unable to find entry starting with " + entryName);
return this.content.entrySet().stream()
.filter(entry -> entry.getKey().startsWith(entryName))
.map(Map.Entry::getValue).findFirst()
.orElseThrow(() -> new IllegalStateException(
"Unable to find entry starting with " + entryName));
}
public boolean hasEntry(String entry) {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -156,12 +156,11 @@ public abstract class LoggingSystem {
}
return get(classLoader, loggingSystem);
}
for (Map.Entry<String, String> entry : SYSTEMS.entrySet()) {
if (ClassUtils.isPresent(entry.getKey(), classLoader)) {
return get(classLoader, entry.getValue());
}
}
throw new IllegalStateException("No suitable logging system located");
return SYSTEMS.entrySet().stream()
.filter((entry) -> ClassUtils.isPresent(entry.getKey(), classLoader))
.map((entry) -> get(classLoader, entry.getValue())).findFirst()
.orElseThrow(() -> new IllegalStateException(
"No suitable logging system located"));
}
private static LoggingSystem get(ClassLoader classLoader, String loggingSystemClass) {

Loading…
Cancel
Save