From d124a13eb4d7bcf70a063c81da2fea5f941f8140 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 11 Mar 2016 15:07:59 +0100 Subject: [PATCH] Consistent use of empty enumerations --- .../mock/web/MockServletContext.java | 11 ++++------- .../web/portlet/ServletWrappingPortletContext.java | 5 ++--- .../web/filter/ForwardedHeaderFilter.java | 12 ++---------- .../mock/web/test/MockServletContext.java | 11 ++++------- .../portlet/handler/SimplePortletPostProcessor.java | 13 ++++++------- .../web/portlet/mvc/PortletWrappingController.java | 11 +++++------ .../web/portlet/ServletWrappingPortletContext.java | 7 +++---- .../servlet/handler/SimpleServletPostProcessor.java | 5 ++--- .../web/servlet/view/freemarker/FreeMarkerView.java | 5 ++--- 9 files changed, 30 insertions(+), 50 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java index 8be8a9a147..7bca348a74 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.EventListener; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -144,7 +143,7 @@ public class MockServletContext implements ServletContext { private String servletContextName = "MockServletContext"; - private final Set declaredRoles = new HashSet(); + private final Set declaredRoles = new LinkedHashSet(); private Set sessionTrackingModes; @@ -370,7 +369,6 @@ public class MockServletContext implements ServletContext { /** * Register a {@link RequestDispatcher} (typically a {@link MockRequestDispatcher}) * that acts as a wrapper for the named Servlet. - * * @param name the name of the wrapped Servlet * @param requestDispatcher the dispatcher that wraps the named Servlet * @see #getNamedDispatcher @@ -384,7 +382,6 @@ public class MockServletContext implements ServletContext { /** * Unregister the {@link RequestDispatcher} with the given name. - * * @param name the name of the dispatcher to unregister * @see #getNamedDispatcher * @see #registerNamedDispatcher @@ -429,13 +426,13 @@ public class MockServletContext implements ServletContext { @Override @Deprecated public Enumeration getServlets() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override @Deprecated public Enumeration getServletNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java index 66a663e080..716f71b0ef 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.Set; import javax.portlet.PortletContext; import javax.portlet.PortletRequestDispatcher; @@ -156,7 +155,7 @@ public class ServletWrappingPortletContext implements PortletContext { @Override public Enumeration getContainerRuntimeOptions() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } } diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index 5881c36fbe..c21a3ac0c6 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.filter; import java.io.IOException; @@ -37,7 +38,6 @@ import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UrlPathHelper; - /** * Filter that wraps the request in order to override its * {@link HttpServletRequest#getServerName() getServerName()}, @@ -70,11 +70,9 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { /** * Configure a contextPath value that will replace the contextPath of * proxy-forwarded requests. - * *

This is useful when external clients are not aware of the application * context path. However a proxy forwards the request to a URL that includes * a contextPath. - * * @param contextPath the context path; the given value will be sanitized to * ensure it starts with a '/' but does not end with one, or if the context * path is empty (default, root context) it is left as-is. @@ -117,10 +115,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { private static class ForwardedHeaderRequestWrapper extends HttpServletRequestWrapper { - public static final Enumeration EMPTY_HEADER_VALUES = - Collections.enumeration(Collections.emptyList()); - - private final String scheme; private final boolean secure; @@ -137,7 +131,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { private final Map> headers; - public ForwardedHeaderRequestWrapper(HttpServletRequest request, ContextPathHelper pathHelper) { super(request); @@ -228,7 +221,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { @Override public Enumeration getHeaders(String name) { List value = this.headers.get(name); - return (CollectionUtils.isEmpty(value) ? EMPTY_HEADER_VALUES : Collections.enumeration(value)); + return (Collections.enumeration(value != null ? value : Collections.emptySet())); } @Override @@ -244,7 +237,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { private final UrlPathHelper urlPathHelper; - public ContextPathHelper(String contextPath) { Assert.notNull(contextPath); this.contextPath = sanitizeContextPath(contextPath); diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java index 224374c003..acaef598c3 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.EventListener; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -144,7 +143,7 @@ public class MockServletContext implements ServletContext { private String servletContextName = "MockServletContext"; - private final Set declaredRoles = new HashSet(); + private final Set declaredRoles = new LinkedHashSet(); private Set sessionTrackingModes; @@ -370,7 +369,6 @@ public class MockServletContext implements ServletContext { /** * Register a {@link RequestDispatcher} (typically a {@link MockRequestDispatcher}) * that acts as a wrapper for the named Servlet. - * * @param name the name of the wrapped Servlet * @param requestDispatcher the dispatcher that wraps the named Servlet * @see #getNamedDispatcher @@ -384,7 +382,6 @@ public class MockServletContext implements ServletContext { /** * Unregister the {@link RequestDispatcher} with the given name. - * * @param name the name of the dispatcher to unregister * @see #getNamedDispatcher * @see #registerNamedDispatcher @@ -429,13 +426,13 @@ public class MockServletContext implements ServletContext { @Override @Deprecated public Enumeration getServlets() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override @Deprecated public Enumeration getServletNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/handler/SimplePortletPostProcessor.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/handler/SimplePortletPostProcessor.java index bd1e8572d6..ba3939489d 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/handler/SimplePortletPostProcessor.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/handler/SimplePortletPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.web.portlet.handler; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; @@ -175,7 +174,7 @@ public class SimplePortletPostProcessor @Override public Enumeration getInitParameterNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override @@ -185,7 +184,7 @@ public class SimplePortletPostProcessor @Override public Enumeration getPublicRenderParameterNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override @@ -195,17 +194,17 @@ public class SimplePortletPostProcessor @Override public Enumeration getPublishingEventQNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override public Enumeration getProcessingEventQNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override public Enumeration getSupportedLocales() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java index 57d1d1233c..e14cf7ea7e 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.web.portlet.mvc; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; @@ -288,7 +287,7 @@ public class PortletWrappingController extends AbstractController @Override public Enumeration getPublicRenderParameterNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override @@ -298,17 +297,17 @@ public class PortletWrappingController extends AbstractController @Override public Enumeration getPublishingEventQNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override public Enumeration getProcessingEventQNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override public Enumeration getSupportedLocales() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } @Override diff --git a/spring-webmvc-portlet/src/test/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java b/spring-webmvc-portlet/src/test/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java index 545f159e28..716f71b0ef 100644 --- a/spring-webmvc-portlet/src/test/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java +++ b/spring-webmvc-portlet/src/test/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.Set; import javax.portlet.PortletContext; import javax.portlet.PortletRequestDispatcher; @@ -35,7 +34,7 @@ import org.springframework.util.Assert; * * @author Juergen Hoeller * @since 3.0 - * @see org.springframework.mock.web.portlet.MockPortletContext + * @see MockPortletContext */ public class ServletWrappingPortletContext implements PortletContext { @@ -156,7 +155,7 @@ public class ServletWrappingPortletContext implements PortletContext { @Override public Enumeration getContainerRuntimeOptions() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java index a83c99d594..d6fef3b68c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.web.servlet.handler; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -164,7 +163,7 @@ public class SimpleServletPostProcessor implements @Override public Enumeration getInitParameterNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java index 991cea244f..00e678f136 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.Locale; import java.util.Map; import javax.servlet.GenericServlet; @@ -406,7 +405,7 @@ public class FreeMarkerView extends AbstractTemplateView { @Override public Enumeration getInitParameterNames() { - return Collections.enumeration(new HashSet()); + return Collections.enumeration(Collections.emptySet()); } }