Polish "Iterate map by using lambda function"

See gh-12528
pull/12436/merge
Phillip Webb 7 years ago
parent ffc883b005
commit 78534a753d

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ public abstract class AbstractHealthAggregator implements HealthAggregator {
@Override @Override
public final Health aggregate(Map<String, Health> healths) { public final Health aggregate(Map<String, Health> healths) {
List<Status> statusCandidates = new ArrayList<>(); List<Status> statusCandidates = new ArrayList<>();
healths.values().forEach(health -> statusCandidates.add(health.getStatus())); healths.values().forEach((health) -> statusCandidates.add(health.getStatus()));
Status status = aggregateStatus(statusCandidates); Status status = aggregateStatus(statusCandidates);
Map<String, Object> details = aggregateDetails(healths); Map<String, Object> details = aggregateDetails(healths);
return new Health.Builder(status, details).build(); return new Health.Builder(status, details).build();

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -196,39 +196,39 @@ public class CloudFoundryVcapEnvironmentPostProcessor
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void flatten(Properties properties, Map<String, Object> input, String path) { private void flatten(Properties properties, Map<String, Object> input, String path) {
input.forEach((entryKey, value) -> { input.forEach((key, value) -> {
String key = getFullKey(path, entryKey); String name = getPropertyName(path, key);
if (value instanceof Map) { if (value instanceof Map) {
// Need a compound key // Need a compound key
flatten(properties, (Map<String, Object>) value, key); flatten(properties, (Map<String, Object>) value, name);
} }
else if (value instanceof Collection) { else if (value instanceof Collection) {
// Need a compound key // Need a compound key
Collection<Object> collection = (Collection<Object>) value; Collection<Object> collection = (Collection<Object>) value;
properties.put(key, properties.put(name,
StringUtils.collectionToCommaDelimitedString(collection)); StringUtils.collectionToCommaDelimitedString(collection));
int count = 0; int count = 0;
for (Object item : collection) { for (Object item : collection) {
String itemKey = "[" + (count++) + "]"; String itemKey = "[" + (count++) + "]";
flatten(properties, Collections.singletonMap(itemKey, item), key); flatten(properties, Collections.singletonMap(itemKey, item), name);
} }
} }
else if (value instanceof String) { else if (value instanceof String) {
properties.put(key, value); properties.put(name, value);
} }
else if (value instanceof Number) { else if (value instanceof Number) {
properties.put(key, value.toString()); properties.put(name, value.toString());
} }
else if (value instanceof Boolean) { else if (value instanceof Boolean) {
properties.put(key, value.toString()); properties.put(name, value.toString());
} }
else { else {
properties.put(key, value == null ? "" : value); properties.put(name, value == null ? "" : value);
} }
}); });
} }
private String getFullKey(String path, String key) { private String getPropertyName(String path, String key) {
if (!StringUtils.hasText(path)) { if (!StringUtils.hasText(path)) {
return key; return key;
} }

@ -246,8 +246,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
} }
private void addLocaleMappings(WebAppContext context) { private void addLocaleMappings(WebAppContext context) {
getLocaleCharsetMappings().forEach((locale, charset) -> getLocaleCharsetMappings().forEach((locale, charset) -> context
context.addLocaleEncoding(locale.toString(), charset.toString())); .addLocaleEncoding(locale.toString(), charset.toString()));
} }
private File getTempDirectory() { private File getTempDirectory() {

@ -232,8 +232,9 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
} }
private void addLocaleMappings(TomcatEmbeddedContext context) { private void addLocaleMappings(TomcatEmbeddedContext context) {
getLocaleCharsetMappings().forEach((locale, charset) -> getLocaleCharsetMappings()
context.addLocaleEncodingMappingParameter(locale.toString(), charset.toString())); .forEach((locale, charset) -> context.addLocaleEncodingMappingParameter(
locale.toString(), charset.toString()));
} }
private void configureTldSkipPatterns(TomcatEmbeddedContext context) { private void configureTldSkipPatterns(TomcatEmbeddedContext context) {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,8 +69,8 @@ class FileSessionPersistence implements SessionPersistenceManager {
private void save(Map<String, PersistentSession> sessionData, private void save(Map<String, PersistentSession> sessionData,
ObjectOutputStream stream) throws IOException { ObjectOutputStream stream) throws IOException {
Map<String, Serializable> session = new LinkedHashMap<>(); Map<String, Serializable> session = new LinkedHashMap<>();
sessionData.forEach((key, value) -> sessionData.forEach((key, value) -> session.put(key,
session.put(key, new SerializablePersistentSession(value))); new SerializablePersistentSession(value)));
stream.writeObject(session); stream.writeObject(session);
} }

@ -328,8 +328,8 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
} }
private void addLocaleMappings(DeploymentInfo deployment) { private void addLocaleMappings(DeploymentInfo deployment) {
getLocaleCharsetMappings().forEach((locale, charset) -> getLocaleCharsetMappings().forEach((locale, charset) -> deployment
deployment.addLocaleCharsetMapping(locale.toString(), charset.toString())); .addLocaleCharsetMapping(locale.toString(), charset.toString()));
} }
private void registerServletContainerInitializerToDriveServletContextInitializers( private void registerServletContainerInitializerToDriveServletContextInitializers(

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -79,7 +79,7 @@ public class ServletContextInitializerBeans
addServletContextInitializerBeans(beanFactory); addServletContextInitializerBeans(beanFactory);
addAdaptableBeans(beanFactory); addAdaptableBeans(beanFactory);
List<ServletContextInitializer> sortedInitializers = new ArrayList<>(); List<ServletContextInitializer> sortedInitializers = new ArrayList<>();
this.initializers.values().forEach(contextInitializers -> { this.initializers.values().forEach((contextInitializers) -> {
AnnotationAwareOrderComparator.sort(contextInitializers); AnnotationAwareOrderComparator.sort(contextInitializers);
sortedInitializers.addAll(contextInitializers); sortedInitializers.addAll(contextInitializers);
}); });

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

Loading…
Cancel
Save