提交 9ca8681f 编写于 作者: S stsypanov 提交者: Juergen Hoeller

Iteration over a map using EntrySet

上级 785e8d81
......@@ -640,9 +640,10 @@ public abstract class AbstractMethodMessageHandler<T>
if (method != null) {
return new InvocableHandlerMethod(handlerMethod.getBean(), method);
}
for (MessagingAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) {
for (Map.Entry<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver> entry : this.exceptionHandlerAdviceCache.entrySet()) {
MessagingAdviceBean advice = entry.getKey();
if (advice.isApplicableToBeanType(beanType)) {
resolver = this.exceptionHandlerAdviceCache.get(advice);
resolver = entry.getValue();
method = resolver.resolveMethod(exception);
if (method != null) {
return new InvocableHandlerMethod(advice.resolveBean(), method);
......
......@@ -155,9 +155,10 @@ class InvocableHelper {
exceptionHandlerMethod = new InvocableHandlerMethod(handlerMethod.getBean(), method);
}
else {
for (MessagingAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) {
for (Map.Entry<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver> entry : this.exceptionHandlerAdviceCache.entrySet()) {
MessagingAdviceBean advice = entry.getKey();
if (advice.isApplicableToBeanType(beanType)) {
resolver = this.exceptionHandlerAdviceCache.get(advice);
resolver = entry.getValue();
method = resolver.resolveMethod(ex);
if (method != null) {
exceptionHandlerMethod = new InvocableHandlerMethod(advice.resolveBean(), method);
......
......@@ -759,8 +759,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
*/
protected void initJaxbMarshaller(Marshaller marshaller) throws JAXBException {
if (this.marshallerProperties != null) {
for (String name : this.marshallerProperties.keySet()) {
marshaller.setProperty(name, this.marshallerProperties.get(name));
for (Map.Entry<String, ?> entry : this.marshallerProperties.entrySet()) {
marshaller.setProperty(entry.getKey(), entry.getValue());
}
}
if (this.marshallerListener != null) {
......@@ -913,8 +913,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
*/
protected void initJaxbUnmarshaller(Unmarshaller unmarshaller) throws JAXBException {
if (this.unmarshallerProperties != null) {
for (String name : this.unmarshallerProperties.keySet()) {
unmarshaller.setProperty(name, this.unmarshallerProperties.get(name));
for (Map.Entry<String, ?> entry : this.unmarshallerProperties.entrySet()) {
unmarshaller.setProperty(entry.getKey(), entry.getValue());
}
}
if (this.unmarshallerListener != null) {
......
......@@ -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;
......
......@@ -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());
}
}
......
......@@ -351,10 +351,11 @@ class ControllerMethodResolver {
if (targetMethod == null) {
// Global exception handlers...
for (ControllerAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) {
for (Map.Entry<ControllerAdviceBean, ExceptionHandlerMethodResolver> entry : this.exceptionHandlerAdviceCache.entrySet()) {
ControllerAdviceBean advice = entry.getKey();
if (advice.isApplicableToBeanType(handlerType)) {
targetBean = advice.resolveBean();
targetMethod = this.exceptionHandlerAdviceCache.get(advice).resolveMethodByThrowable(ex);
targetMethod = entry.getValue().resolveMethodByThrowable(ex);
if (targetMethod != null) {
break;
}
......
......@@ -213,9 +213,9 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle
return cacheControl;
}
// Pattern match?
for (String registeredPath : this.cacheControlMappings.keySet()) {
if (this.pathMatcher.match(registeredPath, urlPath)) {
return this.cacheControlMappings.get(registeredPath);
for (Map.Entry<String, CacheControl> entry : this.cacheControlMappings.entrySet()) {
if (this.pathMatcher.match(entry.getKey(), urlPath)) {
return entry.getValue();
}
}
return null;
......@@ -238,9 +238,9 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle
return cacheSeconds;
}
// Pattern match?
for (String registeredPath : this.cacheMappings.keySet()) {
if (this.pathMatcher.match(registeredPath, urlPath)) {
return this.cacheMappings.get(registeredPath);
for (Map.Entry<String, Integer> entry : this.cacheMappings.entrySet()) {
if (this.pathMatcher.match(entry.getKey(), urlPath)) {
return entry.getValue();
}
}
return null;
......
......@@ -19,6 +19,7 @@ package org.springframework.web.servlet.support;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -169,12 +170,12 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
}
MultiValueMap<String, String> actualParams = getOriginatingRequestParams(request);
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
for (Map.Entry<String, List<String>> entry : expectedParams.entrySet()) {
List<String> actualValues = actualParams.get(entry.getKey());
if (actualValues == null) {
return false;
}
for (String expectedValue : expectedParams.get(expectedName)) {
for (String expectedValue : entry.getValue()) {
if (!actualValues.contains(expectedValue)) {
return false;
}
......
......@@ -485,8 +485,8 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen
writeOptionalAttribute(tagWriter, ONKEYDOWN_ATTRIBUTE, getOnkeydown());
if (!CollectionUtils.isEmpty(this.dynamicAttributes)) {
for (String attr : this.dynamicAttributes.keySet()) {
tagWriter.writeOptionalAttributeValue(attr, getDisplayString(this.dynamicAttributes.get(attr)));
for (Map.Entry<String, Object> entry : this.dynamicAttributes.entrySet()) {
tagWriter.writeOptionalAttributeValue(entry.getKey(), getDisplayString(entry.getValue()));
}
}
}
......
......@@ -704,9 +704,9 @@ public class FormTag extends AbstractHtmlElementTag {
if (!CollectionUtils.isEmpty(hiddenFields)) {
Assert.state(this.tagWriter != null, "No TagWriter set");
this.tagWriter.appendValue("<div>\n");
for (String name : hiddenFields.keySet()) {
for (Map.Entry<String, String> entry : hiddenFields.entrySet()) {
this.tagWriter.appendValue("<input type=\"hidden\" ");
this.tagWriter.appendValue("name=\"" + name + "\" value=\"" + hiddenFields.get(name) + "\" ");
this.tagWriter.appendValue("name=\"" + entry.getKey() + "\" value=\"" + entry.getValue() + "\" ");
this.tagWriter.appendValue("/>\n");
}
this.tagWriter.appendValue("</div>");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册