Use Map.forEach instead of manual Map.Entry iteration wherever possible SPR-16646

This commit is contained in:
igor-suhorukov
2018-03-28 01:55:03 +03:00
committed by Juergen Hoeller
parent 224d52e032
commit 4aae6a6dda
19 changed files with 74 additions and 99 deletions

View File

@@ -80,11 +80,11 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
*/
public FlashMap addTargetRequestParams(@Nullable MultiValueMap<String, String> params) {
if (params != null) {
for (String key : params.keySet()) {
for (String value : params.get(key)) {
params.forEach((key, values) -> {
for (String value : values) {
addTargetRequestParam(key, value);
}
}
});
}
return this;
}

View File

@@ -86,11 +86,11 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg
}
else {
for (MultiValueMap<String, String> vars : matrixVariables.values()) {
for (String name : vars.keySet()) {
for (String value : vars.get(name)) {
vars.forEach((name, values) -> {
for (String value : values) {
map.add(name, value);
}
}
});
}
}

View File

@@ -111,9 +111,7 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
@Override
public RedirectAttributesModelMap addAllAttributes(@Nullable Map<String, ?> attributes) {
if (attributes != null) {
for (String key : attributes.keySet()) {
addAttribute(key, attributes.get(key));
}
attributes.forEach(this::addAttribute);
}
return this;
}
@@ -125,11 +123,11 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
@Override
public RedirectAttributesModelMap mergeAttributes(@Nullable Map<String, ?> attributes) {
if (attributes != null) {
for (String key : attributes.keySet()) {
attributes.forEach((key, attribute) -> {
if (!containsKey(key)) {
addAttribute(key, attributes.get(key));
addAttribute(key, attribute);
}
}
});
}
return this;
}
@@ -155,9 +153,7 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
@Override
public void putAll(@Nullable Map<? extends String, ? extends Object> map) {
if (map != null) {
for (String key : map.keySet()) {
put(key, formatValue(map.get(key)));
}
map.forEach((key, value) -> put(key, formatValue(value)));
}
}