Refact iterator of Map with Java 8 forEach

See gh-1451
This commit is contained in:
diguage 2017-06-06 01:03:44 +08:00 committed by Stephane Nicoll
parent 5df053c44b
commit dab7a7f0ee
37 changed files with 117 additions and 184 deletions

View File

@ -87,9 +87,10 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
// There is no replacement of existing property values.
if (original != null) {
this.propertyValueList = new ArrayList<>(original.size());
for (Map.Entry<?, ?> entry : original.entrySet()) {
this.propertyValueList.add(new PropertyValue(entry.getKey().toString(), entry.getValue()));
}
original.forEach(
(attrName, attrValue)
-> this.propertyValueList.add(new PropertyValue(attrName.toString(), attrValue))
);
}
else {
this.propertyValueList = new ArrayList<>(0);
@ -151,9 +152,10 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
*/
public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) {
if (other != null) {
for (Map.Entry<?, ?> entry : other.entrySet()) {
addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue()));
}
other.forEach(
(attrName, attrValue)
-> addPropertyValue(new PropertyValue(attrName.toString(), attrValue))
);
}
return this;
}

View File

@ -457,9 +457,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
String actualPropertyName =
(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null);
if (this.customEditors != null) {
for (Map.Entry<Class<?>, PropertyEditor> entry : this.customEditors.entrySet()) {
target.registerCustomEditor(entry.getKey(), entry.getValue());
}
this.customEditors.forEach((clazz, propertyEditor) -> target.registerCustomEditor(clazz, propertyEditor));
}
if (this.customEditorsForPath != null) {
for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) {

View File

@ -72,14 +72,12 @@ public class ConstructorArgumentValues {
*/
public void addArgumentValues(@Nullable ConstructorArgumentValues other) {
if (other != null) {
for (Map.Entry<Integer, ValueHolder> entry : other.indexedArgumentValues.entrySet()) {
addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy());
}
for (ValueHolder valueHolder : other.genericArgumentValues) {
if (!this.genericArgumentValues.contains(valueHolder)) {
addOrMergeGenericArgumentValue(valueHolder.copy());
}
}
other.indexedArgumentValues.forEach(
(index, argValue) -> addOrMergeIndexedArgumentValue(index, argValue.copy())
);
other.genericArgumentValues.stream()
.filter(valueHolder -> !this.genericArgumentValues.contains(valueHolder))
.forEach(valueHolder -> addOrMergeGenericArgumentValue(valueHolder));
}
}

View File

@ -17,6 +17,7 @@
package org.springframework.beans.factory.config;
import java.beans.PropertyEditor;
import java.util.Arrays;
import java.util.Map;
import org.apache.commons.logging.Log;
@ -140,16 +141,10 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, Ordered
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (this.propertyEditorRegistrars != null) {
for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
beanFactory.addPropertyEditorRegistrar(propertyEditorRegistrar);
}
Arrays.stream(this.propertyEditorRegistrars).forEach(beanFactory::addPropertyEditorRegistrar);
}
if (this.customEditors != null) {
for (Map.Entry<Class<?>, Class<? extends PropertyEditor>> entry : this.customEditors.entrySet()) {
Class<?> requiredType = entry.getKey();
Class<? extends PropertyEditor> propertyEditorClass = entry.getValue();
beanFactory.registerCustomEditor(requiredType, propertyEditorClass);
}
this.customEditors.forEach(beanFactory::registerCustomEditor);
}
}

View File

@ -18,7 +18,6 @@ package org.springframework.beans.factory.config;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
@ -123,9 +122,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
@SuppressWarnings({"unchecked", "rawtypes"})
private void merge(Map<String, Object> output, Map<String, Object> map) {
for (Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
map.forEach((key, value) -> {
Object existing = output.get(key);
if (value instanceof Map && existing instanceof Map) {
// Inner cast required by Eclipse IDE.
@ -136,7 +133,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
else {
output.put(key, value);
}
}
});
}
}

View File

@ -202,12 +202,10 @@ public abstract class YamlProcessor {
}
Map<Object, Object> map = (Map<Object, Object>) object;
for (Entry<Object, Object> entry : map.entrySet()) {
Object value = entry.getValue();
map.forEach((key, value) -> {
if (value instanceof Map) {
value = asMap(value);
}
Object key = entry.getKey();
if (key instanceof CharSequence) {
result.put(key.toString(), value);
}
@ -215,7 +213,7 @@ public abstract class YamlProcessor {
// It has to be a map key in this case
result.put("[" + key.toString() + "]", value);
}
}
});
return result;
}

View File

@ -169,9 +169,7 @@ class BeanDefinitionValueResolver {
else if (value instanceof ManagedProperties) {
Properties original = (Properties) value;
Properties copy = new Properties();
for (Map.Entry<Object, Object> propEntry : original.entrySet()) {
Object propKey = propEntry.getKey();
Object propValue = propEntry.getValue();
original.forEach((propKey, propValue) -> {
if (propKey instanceof TypedStringValue) {
propKey = evaluate((TypedStringValue) propKey);
}
@ -184,7 +182,7 @@ class BeanDefinitionValueResolver {
"Error converting Properties key/value pair for " + argName + ": resolved to null");
}
copy.put(propKey, propValue);
}
});
return copy;
}
else if (value instanceof TypedStringValue) {

View File

@ -1225,9 +1225,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
private FactoryAwareOrderSourceProvider createFactoryAwareOrderSourceProvider(Map<String, Object> beans) {
IdentityHashMap<Object, String> instancesToBeanNames = new IdentityHashMap<>();
for (Map.Entry<String, Object> entry : beans.entrySet()) {
instancesToBeanNames.put(entry.getValue(), entry.getKey());
}
beans.forEach((beanName, instance) -> instancesToBeanNames.put(instance, beanName));
return new FactoryAwareOrderSourceProvider(instancesToBeanNames);
}

View File

@ -111,9 +111,7 @@ public class CustomMapEditor extends PropertyEditorSupport {
// Convert Map elements.
Map<?, ?> source = (Map<?, ?>) value;
Map<Object, Object> target = createMap(this.mapType, source.size());
for (Map.Entry<?, ?> entry : source.entrySet()) {
target.put(convertKey(entry.getKey()), convertValue(entry.getValue()));
}
source.forEach((key, val) -> target.put(convertKey(key), convertValue(val)));
super.setValue(target);
}
else {

View File

@ -57,9 +57,7 @@ public class NameMatchCacheOperationSource implements CacheOperationSource, Seri
* @see CacheOperation
*/
public void setNameMap(Map<String, Collection<CacheOperation>> nameMap) {
for (Map.Entry<String, Collection<CacheOperation>> entry : nameMap.entrySet()) {
addCacheMethod(entry.getKey(), entry.getValue());
}
nameMap.forEach(this::addCacheMethod);
}
/**

View File

@ -351,9 +351,7 @@ class ConfigurationClassBeanDefinitionReader {
}
private void loadBeanDefinitionsFromRegistrars(Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> registrars) {
for (Map.Entry<ImportBeanDefinitionRegistrar, AnnotationMetadata> entry : registrars.entrySet()) {
entry.getKey().registerBeanDefinitions(entry.getValue(), this.registry);
}
registrars.forEach((registrar, metadata) -> registrar.registerBeanDefinitions(metadata, this.registry));
}

View File

@ -75,13 +75,12 @@ public class CandidateComponentsIndex {
private static MultiValueMap<String, String> parseIndex(List<Properties> content) {
MultiValueMap<String, String> index = new LinkedMultiValueMap<>();
for (Properties entry : content) {
for (Map.Entry<Object, Object> entries : entry.entrySet()) {
String type = (String) entries.getKey();
String[] stereotypes = ((String) entries.getValue()).split(",");
entry.forEach((type, values) -> {
String[] stereotypes = ((String) values).split(",");
for (String stereotype : stereotypes) {
index.add(stereotype, type);
index.add(stereotype, (String) type);
}
}
});
}
return index;
}

View File

@ -132,8 +132,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
private void startBeans(boolean autoStartupOnly) {
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
Map<Integer, LifecycleGroup> phases = new HashMap<>();
for (Map.Entry<String, ? extends Lifecycle> entry : lifecycleBeans.entrySet()) {
Lifecycle bean = entry.getValue();
lifecycleBeans.forEach((beanName, bean) -> {
if (!autoStartupOnly || (bean instanceof SmartLifecycle && ((SmartLifecycle) bean).isAutoStartup())) {
int phase = getPhase(bean);
LifecycleGroup group = phases.get(phase);
@ -141,9 +140,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
group = new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly);
phases.put(phase, group);
}
group.add(entry.getKey(), bean);
group.add(beanName, bean);
}
}
});
if (!phases.isEmpty()) {
List<Integer> keys = new ArrayList<>(phases.keySet());
Collections.sort(keys);
@ -187,16 +186,15 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
private void stopBeans() {
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
Map<Integer, LifecycleGroup> phases = new HashMap<>();
for (Map.Entry<String, Lifecycle> entry : lifecycleBeans.entrySet()) {
Lifecycle bean = entry.getValue();
lifecycleBeans.forEach((beanName, bean) -> {
int shutdownOrder = getPhase(bean);
LifecycleGroup group = phases.get(shutdownOrder);
if (group == null) {
group = new LifecycleGroup(shutdownOrder, this.timeoutPerShutdownPhase, lifecycleBeans, false);
phases.put(shutdownOrder, group);
}
group.add(entry.getKey(), bean);
}
group.add(beanName, bean);
});
if (!phases.isEmpty()) {
List<Integer> keys = new ArrayList<>(phases.keySet());
Collections.sort(keys, Collections.reverseOrder());

View File

@ -87,9 +87,7 @@ public class StaticMessageSource extends AbstractMessageSource {
*/
public void addMessages(Map<String, String> messages, Locale locale) {
Assert.notNull(messages, "Messages Map must not be null");
for (Map.Entry<String, String> entry : messages.entrySet()) {
addMessage(entry.getKey(), locale, entry.getValue());
}
messages.forEach((code, msg) -> addMessage(code, locale, msg));
}

View File

@ -367,17 +367,16 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
List<NotificationListenerBean> notificationListeners =
new ArrayList<>(listeners.size());
for (Map.Entry<?, ? extends NotificationListener> entry : listeners.entrySet()) {
listeners.forEach((key, listener) -> {
// Get the listener from the map value.
NotificationListenerBean bean = new NotificationListenerBean(entry.getValue());
NotificationListenerBean bean = new NotificationListenerBean(listener);
// Get the ObjectName from the map key.
Object key = entry.getKey();
if (key != null && !WILDCARD.equals(key)) {
// This listener is mapped to a specific ObjectName.
bean.setMappedObjectName(entry.getKey());
bean.setMappedObjectName(key);
}
notificationListeners.add(bean);
}
});
this.notificationListeners =
notificationListeners.toArray(new NotificationListenerBean[notificationListeners.size()]);
@ -545,9 +544,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
}
if (!this.beans.isEmpty()) {
for (Map.Entry<String, Object> entry : this.beans.entrySet()) {
registerBeanNameOrInstance(entry.getValue(), entry.getKey());
}
this.beans.forEach((beanName, instance) -> registerBeanNameOrInstance(instance, beanName));
}
}
@ -1008,9 +1005,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
* from the {@link MBeanServer}.
*/
private void unregisterNotificationListeners() {
for (Map.Entry<NotificationListenerBean, ObjectName[]> entry : this.registeredNotificationListeners.entrySet()) {
NotificationListenerBean bean = entry.getKey();
ObjectName[] mappedObjectNames = entry.getValue();
this.registeredNotificationListeners.forEach((bean, mappedObjectNames) -> {
for (ObjectName mappedObjectName : mappedObjectNames) {
try {
this.server.removeNotificationListener(mappedObjectName, bean.getNotificationListener(),
@ -1022,7 +1017,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
}
}
}
}
});
this.registeredNotificationListeners.clear();
}

View File

@ -53,9 +53,10 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
}
public void setNotificationInfoMappings(Map<String, Object> notificationInfoMappings) {
for (Map.Entry<String, Object> entry : notificationInfoMappings.entrySet()) {
this.notificationInfoMappings.put(entry.getKey(), extractNotificationMetadata(entry.getValue()));
}
notificationInfoMappings.forEach(
(beanKey, result)
-> this.notificationInfoMappings.put(beanKey, extractNotificationMetadata(result))
);
}

View File

@ -315,12 +315,11 @@ public class ScheduledAnnotationBeanPostProcessor
}
else {
// Non-empty set of methods
for (Map.Entry<Method, Set<Scheduled>> entry : annotatedMethods.entrySet()) {
Method method = entry.getKey();
for (Scheduled scheduled : entry.getValue()) {
annotatedMethods.forEach((method, scheduleds) -> {
for (Scheduled scheduled : scheduleds) {
processScheduled(scheduled, method, bean);
}
}
});
if (logger.isDebugEnabled()) {
logger.debug(annotatedMethods.size() + " @Scheduled methods processed on bean '" + beanName +
"': " + annotatedMethods);

View File

@ -114,9 +114,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public void setTriggerTasks(Map<Runnable, Trigger> triggerTasks) {
this.triggerTasks = new ArrayList<>();
for (Map.Entry<Runnable, Trigger> task : triggerTasks.entrySet()) {
addTriggerTask(new TriggerTask(task.getKey(), task.getValue()));
}
triggerTasks.forEach((task, trigger) -> addTriggerTask(new TriggerTask(task, trigger)));
}
/**
@ -145,9 +143,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public void setCronTasks(Map<Runnable, String> cronTasks) {
this.cronTasks = new ArrayList<>();
for (Map.Entry<Runnable, String> task : cronTasks.entrySet()) {
addCronTask(task.getKey(), task.getValue());
}
cronTasks.forEach(this::addCronTask);
}
/**
@ -176,9 +172,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public void setFixedRateTasks(Map<Runnable, Long> fixedRateTasks) {
this.fixedRateTasks = new ArrayList<>();
for (Map.Entry<Runnable, Long> task : fixedRateTasks.entrySet()) {
addFixedRateTask(task.getKey(), task.getValue());
}
fixedRateTasks.forEach(this::addFixedRateTask);
}
/**
@ -207,9 +201,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public void setFixedDelayTasks(Map<Runnable, Long> fixedDelayTasks) {
this.fixedDelayTasks = new ArrayList<>();
for (Map.Entry<Runnable, Long> task : fixedDelayTasks.entrySet()) {
addFixedDelayTask(task.getKey(), task.getValue());
}
fixedDelayTasks.forEach(this::addFixedDelayTask);
}
/**

View File

@ -126,12 +126,11 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
*/
public ConcurrentModel mergeAttributes(@Nullable Map<String, ?> attributes) {
if (attributes != null) {
for (Map.Entry<String, ?> entry : attributes.entrySet()) {
String key = entry.getKey();
attributes.forEach((key, value) -> {
if (!containsKey(key)) {
put(key, entry.getValue());
put(key, value);
}
}
});
}
return this;
}

View File

@ -126,12 +126,11 @@ public class ModelMap extends LinkedHashMap<String, Object> {
*/
public ModelMap mergeAttributes(@Nullable Map<String, ?> attributes) {
if (attributes != null) {
for (Map.Entry<String, ?> entry : attributes.entrySet()) {
String key = entry.getKey();
attributes.forEach((key, value) -> {
if (!containsKey(key)) {
put(key, entry.getValue());
put(key, value);
}
}
});
}
return this;
}

View File

@ -287,9 +287,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
}
}
for (Map.Entry<String, String> entry : this.validationPropertyMap.entrySet()) {
configuration.addProperty(entry.getKey(), entry.getValue());
}
this.validationPropertyMap.forEach(configuration::addProperty);
// Allow for custom post-processing before we actually build the ValidatorFactory.
postProcessConfiguration(configuration);

View File

@ -215,16 +215,14 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
arguments.add(getResolvableField(objectName, field));
// Using a TreeMap for alphabetical ordering of attribute names
Map<String, Object> attributesToExpose = new TreeMap<>();
for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
String attributeName = entry.getKey();
Object attributeValue = entry.getValue();
descriptor.getAttributes().forEach((attributeName, attributeValue) -> {
if (!internalAnnotationAttributes.contains(attributeName)) {
if (attributeValue instanceof String) {
attributeValue = new ResolvableAttribute(attributeValue.toString());
}
attributesToExpose.put(attributeName, attributeValue);
}
}
});
arguments.addAll(attributesToExpose.values());
return arguments.toArray(new Object[arguments.size()]);
}

View File

@ -46,9 +46,7 @@ public class BindingAwareModelMap extends ExtendedModelMap {
@Override
public void putAll(Map<? extends String, ?> map) {
for (Map.Entry<? extends String, ?> entry : map.entrySet()) {
removeBindingResultIfNecessary(entry.getKey(), entry.getValue());
}
map.forEach(this::removeBindingResultIfNecessary);
super.putAll(map);
}

View File

@ -118,14 +118,12 @@ public class SimpleAliasRegistry implements AliasRegistry {
* @param result the resulting aliases list
*/
private void retrieveAliases(String name, List<String> result) {
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) {
String registeredName = entry.getValue();
this.aliasMap.forEach((alias, registeredName) -> {
if (registeredName.equals(name)) {
String alias = entry.getKey();
result.add(alias);
retrieveAliases(alias, result);
}
}
});
}
/**

View File

@ -580,9 +580,7 @@ public class AnnotatedElementUtils {
public Object process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
AnnotationAttributes annotationAttributes = AnnotationUtils.getAnnotationAttributes(
annotation, classValuesAsString, nestedAnnotationsAsMap);
for (Map.Entry<String, Object> entry : annotationAttributes.entrySet()) {
attributesMap.add(entry.getKey(), entry.getValue());
}
annotationAttributes.forEach(attributesMap::add);
return CONTINUE;
}
});

View File

@ -147,9 +147,7 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho
for (AnnotationAttributes annotationAttributes : attributesList) {
AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues(
"method '" + getMethodName() + "'", this.classLoader, annotationAttributes, classValuesAsString);
for (Map.Entry<String, Object> entry : convertedAttributes.entrySet()) {
allAttributes.add(entry.getKey(), entry.getValue());
}
convertedAttributes.forEach((attrName, attrValue) -> allAttributes.add(attrName, attrValue));
}
}
return allAttributes;

View File

@ -175,12 +175,10 @@ public class MimeType implements Comparable<MimeType>, Serializable {
this.subtype = subtype.toLowerCase(Locale.ENGLISH);
if (!CollectionUtils.isEmpty(parameters)) {
Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
String attribute = entry.getKey();
String value = entry.getValue();
parameters.forEach((attribute, value) -> {
checkParameters(attribute, value);
map.put(attribute, value);
}
});
this.parameters = Collections.unmodifiableMap(map);
}
else {
@ -456,12 +454,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
private void appendTo(Map<String, String> map, StringBuilder builder) {
for (Map.Entry<String, String> entry : map.entrySet()) {
builder.append(';');
builder.append(entry.getKey());
map.forEach((key, val) -> {
builder.append(";");
builder.append(key);
builder.append('=');
builder.append(entry.getValue());
}
builder.append(val);
});
}
/**

View File

@ -99,9 +99,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
* The supplied map must consist of string key value pairs.
*/
public void setBindings(Map<String, String> bindings) {
for (Map.Entry<String, String> entry : bindings.entrySet()) {
bindNamespaceUri(entry.getKey(), entry.getValue());
}
bindings.forEach(this::bindNamespaceUri);
}
/**

View File

@ -99,11 +99,10 @@ class StaxEventHandler extends AbstractStaxHandler {
private List<Namespace> getNamespaces(Map<String, String> namespaceMapping) {
List<Namespace> result = new ArrayList<>();
for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) {
String prefix = entry.getKey();
String namespaceUri = entry.getValue();
result.add(this.eventFactory.createNamespace(prefix, namespaceUri));
}
namespaceMapping.forEach(
(prefix, namespaceUri)
-> result.add(this.eventFactory.createNamespace(prefix, namespaceUri))
);
return result;
}

View File

@ -369,9 +369,7 @@ public class GenericConversionServiceTests {
watch.start("convert 4,000,000 manually");
for (int i = 0; i < 4000000; i++) {
Map<String, Integer> target = new HashMap<>(source.size());
for (Map.Entry<String, String> entry : source.entrySet()) {
target.put(entry.getKey(), Integer.valueOf(entry.getValue()));
}
source.forEach((k, v) -> target.put(k, Integer.valueOf(v)));
}
watch.stop();
// System.out.println(watch.prettyPrint());

View File

@ -66,17 +66,17 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder {
String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
if (uriVars != null) {
for (Entry<String, String> entry : uriVars.entrySet()) {
if (mpvs.contains(entry.getKey())) {
uriVars.forEach((name, value) -> {
if (mpvs.contains(name)) {
if (logger.isWarnEnabled()) {
logger.warn("Skipping URI variable '" + entry.getKey() +
logger.warn("Skipping URI variable '" + name +
"' since the request contains a bind value with the same name.");
}
}
else {
mpvs.addPropertyValue(entry.getKey(), entry.getValue());
mpvs.addPropertyValue(name, value);
}
}
});
}
}

View File

@ -187,11 +187,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
}
}
if (!entityHeaders.isEmpty()) {
for (Map.Entry<String, List<String>> entry : entityHeaders.entrySet()) {
if (!outputHeaders.containsKey(entry.getKey())) {
outputHeaders.put(entry.getKey(), entry.getValue());
entityHeaders.forEach((key, value) -> {
if (!outputHeaders.containsKey(key)) {
outputHeaders.put(key, value);
}
}
});
}
if (responseEntity instanceof ResponseEntity) {

View File

@ -889,14 +889,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
List<InvocableHandlerMethod> attrMethods = new ArrayList<>();
// Global methods first
for (Entry<ControllerAdviceBean, Set<Method>> entry : this.modelAttributeAdviceCache.entrySet()) {
if (entry.getKey().isApplicableToBeanType(handlerType)) {
Object bean = entry.getKey().resolveBean();
for (Method method : entry.getValue()) {
this.modelAttributeAdviceCache.forEach((clazz, methodSet) -> {
if (clazz.isApplicableToBeanType(handlerType)) {
Object bean = clazz.resolveBean();
for (Method method : methodSet) {
attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
}
}
}
});
for (Method method : methods) {
Object bean = handlerMethod.getBean();
attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
@ -921,14 +921,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
List<InvocableHandlerMethod> initBinderMethods = new ArrayList<>();
// Global methods first
for (Entry<ControllerAdviceBean, Set<Method>> entry : this.initBinderAdviceCache.entrySet()) {
if (entry.getKey().isApplicableToBeanType(handlerType)) {
Object bean = entry.getKey().resolveBean();
for (Method method : entry.getValue()) {
this.initBinderAdviceCache.forEach((clazz, methodSet) -> {
if (clazz.isApplicableToBeanType(handlerType)) {
Object bean = clazz.resolveBean();
for (Method method : methodSet) {
initBinderMethods.add(createInitBinderMethod(bean, method));
}
}
}
});
for (Method method : methods) {
Object bean = handlerMethod.getBean();
initBinderMethods.add(createInitBinderMethod(bean, method));

View File

@ -196,9 +196,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
*/
public void setAttributesMap(@Nullable Map<String, ?> attributes) {
if (attributes != null) {
for (Map.Entry<String, ?> entry : attributes.entrySet()) {
addStaticAttribute(entry.getKey(), entry.getValue());
}
attributes.forEach(this::addStaticAttribute);
}
}
@ -429,9 +427,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
* @param request current HTTP request
*/
protected void exposeModelAsRequestAttributes(Map<String, Object> model, HttpServletRequest request) throws Exception {
for (Map.Entry<String, Object> entry : model.entrySet()) {
String modelName = entry.getKey();
Object modelValue = entry.getValue();
model.forEach((modelName, modelValue) -> {
if (modelValue != null) {
request.setAttribute(modelName, modelValue);
if (logger.isDebugEnabled()) {
@ -446,7 +442,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
"' from request in view with name '" + getBeanName() + "'");
}
}
}
});
}
/**

View File

@ -487,11 +487,11 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
*/
protected Map<String, Object> queryProperties(Map<String, Object> model) {
Map<String, Object> result = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry : model.entrySet()) {
if (isEligibleProperty(entry.getKey(), entry.getValue())) {
result.put(entry.getKey(), entry.getValue());
model.forEach((name, value) -> {
if (isEligibleProperty(name, value)) {
result.put(name, value);
}
}
});
return result;
}

View File

@ -217,13 +217,13 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
protected Object filterModel(Map<String, Object> model) {
Map<String, Object> result = new HashMap<>(model.size());
Set<String> modelKeys = (!CollectionUtils.isEmpty(this.modelKeys) ? this.modelKeys : model.keySet());
for (Map.Entry<String, Object> entry : model.entrySet()) {
if (!(entry.getValue() instanceof BindingResult) && modelKeys.contains(entry.getKey()) &&
!entry.getKey().equals(JsonView.class.getName()) &&
!entry.getKey().equals(FilterProvider.class.getName())) {
result.put(entry.getKey(), entry.getValue());
model.forEach((clazz, value) -> {
if (!(value instanceof BindingResult) && modelKeys.contains(clazz) &&
!clazz.equals(JsonView.class.getName()) &&
!clazz.equals(FilterProvider.class.getName())) {
result.put(clazz, value);
}
}
});
return (this.extractValueFromSingleKeyModel && result.size() == 1 ? result.values().iterator().next() : result);
}

View File

@ -380,9 +380,7 @@ public class XsltView extends AbstractUrlBasedView {
* @param transformer the target transformer
*/
protected final void copyModelParameters(Map<String, Object> model, Transformer transformer) {
for (Map.Entry<String, Object> entry : model.entrySet()) {
transformer.setParameter(entry.getKey(), entry.getValue());
}
model.forEach(transformer::setParameter);
}
/**