Iteration over a map using EntrySet

This commit is contained in:
stsypanov
2019-05-13 14:27:01 +03:00
committed by Juergen Hoeller
parent 785e8d8116
commit 9ca8681f79
10 changed files with 45 additions and 36 deletions

View File

@@ -95,9 +95,9 @@ class HeaderValueHolder {
@Nullable
public static HeaderValueHolder getByName(Map<String, HeaderValueHolder> headers, String name) {
Assert.notNull(name, "Header name must not be null");
for (String headerName : headers.keySet()) {
if (headerName.equalsIgnoreCase(name)) {
return headers.get(headerName);
for (Map.Entry<String, HeaderValueHolder> entry : headers.entrySet()) {
if (entry.getKey().equalsIgnoreCase(name)) {
return entry.getValue();
}
}
return null;

View File

@@ -530,14 +530,16 @@ public class MockHttpServletRequestBuilder
this.contentType = parentBuilder.contentType;
}
for (String headerName : parentBuilder.headers.keySet()) {
for (Map.Entry<String, List<Object>> entry : parentBuilder.headers.entrySet()) {
String headerName = entry.getKey();
if (!this.headers.containsKey(headerName)) {
this.headers.put(headerName, parentBuilder.headers.get(headerName));
this.headers.put(headerName, entry.getValue());
}
}
for (String paramName : parentBuilder.parameters.keySet()) {
for (Map.Entry<String, List<String>> entry : parentBuilder.parameters.entrySet()) {
String paramName = entry.getKey();
if (!this.parameters.containsKey(paramName)) {
this.parameters.put(paramName, parentBuilder.parameters.get(paramName));
this.parameters.put(paramName, entry.getValue());
}
}
for (Cookie cookie : parentBuilder.cookies) {
@@ -551,19 +553,22 @@ public class MockHttpServletRequestBuilder
}
}
for (String attributeName : parentBuilder.requestAttributes.keySet()) {
for (Map.Entry<String, Object> entry : parentBuilder.requestAttributes.entrySet()) {
String attributeName = entry.getKey();
if (!this.requestAttributes.containsKey(attributeName)) {
this.requestAttributes.put(attributeName, parentBuilder.requestAttributes.get(attributeName));
this.requestAttributes.put(attributeName, entry.getValue());
}
}
for (String attributeName : parentBuilder.sessionAttributes.keySet()) {
for (Map.Entry<String, Object> entry : parentBuilder.sessionAttributes.entrySet()) {
String attributeName = entry.getKey();
if (!this.sessionAttributes.containsKey(attributeName)) {
this.sessionAttributes.put(attributeName, parentBuilder.sessionAttributes.get(attributeName));
this.sessionAttributes.put(attributeName, entry.getValue());
}
}
for (String attributeName : parentBuilder.flashAttributes.keySet()) {
for (Map.Entry<String, Object> entry : parentBuilder.flashAttributes.entrySet()) {
String attributeName = entry.getKey();
if (!this.flashAttributes.containsKey(attributeName)) {
this.flashAttributes.put(attributeName, parentBuilder.flashAttributes.get(attributeName));
this.flashAttributes.put(attributeName, entry.getValue());
}
}