Skip to content

Commit d124a13

Browse files
committed
Consistent use of empty enumerations
1 parent 8852a5e commit d124a13

File tree

9 files changed

+30
-50
lines changed

9 files changed

+30
-50
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
import java.util.Enumeration;
2626
import java.util.EventListener;
2727
import java.util.HashMap;
28-
import java.util.HashSet;
2928
import java.util.LinkedHashMap;
3029
import java.util.LinkedHashSet;
3130
import java.util.Map;
@@ -144,7 +143,7 @@ public class MockServletContext implements ServletContext {
144143

145144
private String servletContextName = "MockServletContext";
146145

147-
private final Set<String> declaredRoles = new HashSet<String>();
146+
private final Set<String> declaredRoles = new LinkedHashSet<String>();
148147

149148
private Set<SessionTrackingMode> sessionTrackingModes;
150149

@@ -370,7 +369,6 @@ public RequestDispatcher getNamedDispatcher(String path) {
370369
/**
371370
* Register a {@link RequestDispatcher} (typically a {@link MockRequestDispatcher})
372371
* that acts as a wrapper for the named Servlet.
373-
*
374372
* @param name the name of the wrapped Servlet
375373
* @param requestDispatcher the dispatcher that wraps the named Servlet
376374
* @see #getNamedDispatcher
@@ -384,7 +382,6 @@ public void registerNamedDispatcher(String name, RequestDispatcher requestDispat
384382

385383
/**
386384
* Unregister the {@link RequestDispatcher} with the given name.
387-
*
388385
* @param name the name of the dispatcher to unregister
389386
* @see #getNamedDispatcher
390387
* @see #registerNamedDispatcher
@@ -429,13 +426,13 @@ public Servlet getServlet(String name) {
429426
@Override
430427
@Deprecated
431428
public Enumeration<Servlet> getServlets() {
432-
return Collections.enumeration(new HashSet<Servlet>());
429+
return Collections.enumeration(Collections.<Servlet>emptySet());
433430
}
434431

435432
@Override
436433
@Deprecated
437434
public Enumeration<String> getServletNames() {
438-
return Collections.enumeration(new HashSet<String>());
435+
return Collections.enumeration(Collections.<String>emptySet());
439436
}
440437

441438
@Override

spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.net.URL;
2222
import java.util.Collections;
2323
import java.util.Enumeration;
24-
import java.util.HashSet;
2524
import java.util.Set;
2625
import javax.portlet.PortletContext;
2726
import javax.portlet.PortletRequestDispatcher;
@@ -156,7 +155,7 @@ public String getPortletContextName() {
156155

157156
@Override
158157
public Enumeration<String> getContainerRuntimeOptions() {
159-
return Collections.enumeration(new HashSet<String>());
158+
return Collections.enumeration(Collections.<String>emptySet());
160159
}
161160

162161
}

spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.filter;
1718

1819
import java.io.IOException;
@@ -37,7 +38,6 @@
3738
import org.springframework.web.util.UriComponentsBuilder;
3839
import org.springframework.web.util.UrlPathHelper;
3940

40-
4141
/**
4242
* Filter that wraps the request in order to override its
4343
* {@link HttpServletRequest#getServerName() getServerName()},
@@ -70,11 +70,9 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
7070
/**
7171
* Configure a contextPath value that will replace the contextPath of
7272
* proxy-forwarded requests.
73-
*
7473
* <p>This is useful when external clients are not aware of the application
7574
* context path. However a proxy forwards the request to a URL that includes
7675
* a contextPath.
77-
*
7876
* @param contextPath the context path; the given value will be sanitized to
7977
* ensure it starts with a '/' but does not end with one, or if the context
8078
* path is empty (default, root context) it is left as-is.
@@ -117,10 +115,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
117115

118116
private static class ForwardedHeaderRequestWrapper extends HttpServletRequestWrapper {
119117

120-
public static final Enumeration<String> EMPTY_HEADER_VALUES =
121-
Collections.enumeration(Collections.<String>emptyList());
122-
123-
124118
private final String scheme;
125119

126120
private final boolean secure;
@@ -137,7 +131,6 @@ private static class ForwardedHeaderRequestWrapper extends HttpServletRequestWra
137131

138132
private final Map<String, List<String>> headers;
139133

140-
141134
public ForwardedHeaderRequestWrapper(HttpServletRequest request, ContextPathHelper pathHelper) {
142135
super(request);
143136

@@ -228,7 +221,7 @@ public String getHeader(String name) {
228221
@Override
229222
public Enumeration<String> getHeaders(String name) {
230223
List<String> value = this.headers.get(name);
231-
return (CollectionUtils.isEmpty(value) ? EMPTY_HEADER_VALUES : Collections.enumeration(value));
224+
return (Collections.enumeration(value != null ? value : Collections.<String>emptySet()));
232225
}
233226

234227
@Override
@@ -244,7 +237,6 @@ private static class ContextPathHelper {
244237

245238
private final UrlPathHelper urlPathHelper;
246239

247-
248240
public ContextPathHelper(String contextPath) {
249241
Assert.notNull(contextPath);
250242
this.contextPath = sanitizeContextPath(contextPath);

spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
import java.util.Enumeration;
2626
import java.util.EventListener;
2727
import java.util.HashMap;
28-
import java.util.HashSet;
2928
import java.util.LinkedHashMap;
3029
import java.util.LinkedHashSet;
3130
import java.util.Map;
@@ -144,7 +143,7 @@ public class MockServletContext implements ServletContext {
144143

145144
private String servletContextName = "MockServletContext";
146145

147-
private final Set<String> declaredRoles = new HashSet<String>();
146+
private final Set<String> declaredRoles = new LinkedHashSet<String>();
148147

149148
private Set<SessionTrackingMode> sessionTrackingModes;
150149

@@ -370,7 +369,6 @@ public RequestDispatcher getNamedDispatcher(String path) {
370369
/**
371370
* Register a {@link RequestDispatcher} (typically a {@link MockRequestDispatcher})
372371
* that acts as a wrapper for the named Servlet.
373-
*
374372
* @param name the name of the wrapped Servlet
375373
* @param requestDispatcher the dispatcher that wraps the named Servlet
376374
* @see #getNamedDispatcher
@@ -384,7 +382,6 @@ public void registerNamedDispatcher(String name, RequestDispatcher requestDispat
384382

385383
/**
386384
* Unregister the {@link RequestDispatcher} with the given name.
387-
*
388385
* @param name the name of the dispatcher to unregister
389386
* @see #getNamedDispatcher
390387
* @see #registerNamedDispatcher
@@ -429,13 +426,13 @@ public Servlet getServlet(String name) {
429426
@Override
430427
@Deprecated
431428
public Enumeration<Servlet> getServlets() {
432-
return Collections.enumeration(new HashSet<Servlet>());
429+
return Collections.enumeration(Collections.<Servlet>emptySet());
433430
}
434431

435432
@Override
436433
@Deprecated
437434
public Enumeration<String> getServletNames() {
438-
return Collections.enumeration(new HashSet<String>());
435+
return Collections.enumeration(Collections.<String>emptySet());
439436
}
440437

441438
@Override

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/handler/SimplePortletPostProcessor.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.util.Collections;
2020
import java.util.Enumeration;
21-
import java.util.HashSet;
2221
import java.util.Locale;
2322
import java.util.Map;
2423
import java.util.ResourceBundle;
@@ -175,7 +174,7 @@ public String getInitParameter(String paramName) {
175174

176175
@Override
177176
public Enumeration<String> getInitParameterNames() {
178-
return Collections.enumeration(new HashSet<String>());
177+
return Collections.enumeration(Collections.<String>emptySet());
179178
}
180179

181180
@Override
@@ -185,7 +184,7 @@ public ResourceBundle getResourceBundle(Locale locale) {
185184

186185
@Override
187186
public Enumeration<String> getPublicRenderParameterNames() {
188-
return Collections.enumeration(new HashSet<String>());
187+
return Collections.enumeration(Collections.<String>emptySet());
189188
}
190189

191190
@Override
@@ -195,17 +194,17 @@ public String getDefaultNamespace() {
195194

196195
@Override
197196
public Enumeration<QName> getPublishingEventQNames() {
198-
return Collections.enumeration(new HashSet<QName>());
197+
return Collections.enumeration(Collections.<QName>emptySet());
199198
}
200199

201200
@Override
202201
public Enumeration<QName> getProcessingEventQNames() {
203-
return Collections.enumeration(new HashSet<QName>());
202+
return Collections.enumeration(Collections.<QName>emptySet());
204203
}
205204

206205
@Override
207206
public Enumeration<Locale> getSupportedLocales() {
208-
return Collections.enumeration(new HashSet<Locale>());
207+
return Collections.enumeration(Collections.<Locale>emptySet());
209208
}
210209

211210
@Override

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.util.Collections;
2020
import java.util.Enumeration;
21-
import java.util.HashSet;
2221
import java.util.LinkedHashMap;
2322
import java.util.Locale;
2423
import java.util.Map;
@@ -288,7 +287,7 @@ public ResourceBundle getResourceBundle(Locale locale) {
288287

289288
@Override
290289
public Enumeration<String> getPublicRenderParameterNames() {
291-
return Collections.enumeration(new HashSet<String>());
290+
return Collections.enumeration(Collections.<String>emptySet());
292291
}
293292

294293
@Override
@@ -298,17 +297,17 @@ public String getDefaultNamespace() {
298297

299298
@Override
300299
public Enumeration<QName> getPublishingEventQNames() {
301-
return Collections.enumeration(new HashSet<QName>());
300+
return Collections.enumeration(Collections.<QName>emptySet());
302301
}
303302

304303
@Override
305304
public Enumeration<QName> getProcessingEventQNames() {
306-
return Collections.enumeration(new HashSet<QName>());
305+
return Collections.enumeration(Collections.<QName>emptySet());
307306
}
308307

309308
@Override
310309
public Enumeration<Locale> getSupportedLocales() {
311-
return Collections.enumeration(new HashSet<Locale>());
310+
return Collections.enumeration(Collections.<Locale>emptySet());
312311
}
313312

314313
@Override

spring-webmvc-portlet/src/test/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.net.URL;
2222
import java.util.Collections;
2323
import java.util.Enumeration;
24-
import java.util.HashSet;
2524
import java.util.Set;
2625
import javax.portlet.PortletContext;
2726
import javax.portlet.PortletRequestDispatcher;
@@ -35,7 +34,7 @@
3534
*
3635
* @author Juergen Hoeller
3736
* @since 3.0
38-
* @see org.springframework.mock.web.portlet.MockPortletContext
37+
* @see MockPortletContext
3938
*/
4039
public class ServletWrappingPortletContext implements PortletContext {
4140

@@ -156,7 +155,7 @@ public String getPortletContextName() {
156155

157156
@Override
158157
public Enumeration<String> getContainerRuntimeOptions() {
159-
return Collections.enumeration(new HashSet<String>());
158+
return Collections.enumeration(Collections.<String>emptySet());
160159
}
161160

162161
}

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.util.Collections;
2020
import java.util.Enumeration;
21-
import java.util.HashSet;
2221
import javax.servlet.Servlet;
2322
import javax.servlet.ServletConfig;
2423
import javax.servlet.ServletContext;
@@ -164,7 +163,7 @@ public String getInitParameter(String paramName) {
164163

165164
@Override
166165
public Enumeration<String> getInitParameterNames() {
167-
return Collections.enumeration(new HashSet<String>());
166+
return Collections.enumeration(Collections.<String>emptySet());
168167
}
169168
}
170169

spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.io.IOException;
2121
import java.util.Collections;
2222
import java.util.Enumeration;
23-
import java.util.HashSet;
2423
import java.util.Locale;
2524
import java.util.Map;
2625
import javax.servlet.GenericServlet;
@@ -406,7 +405,7 @@ public String getInitParameter(String paramName) {
406405

407406
@Override
408407
public Enumeration<String> getInitParameterNames() {
409-
return Collections.enumeration(new HashSet<String>());
408+
return Collections.enumeration(Collections.<String>emptySet());
410409
}
411410
}
412411

0 commit comments

Comments
 (0)