Refact iterator of Map with Java 8 forEach
See gh-1451
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user