Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-27 17:35:44 +00:00
parent b0790bf5e7
commit 85661c6882
49 changed files with 353 additions and 477 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2008 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.
@@ -17,7 +17,6 @@
package org.springframework.web.bind;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.validation.Errors;
@@ -117,7 +116,7 @@ public class EscapedErrors implements Errors {
return this.source.getErrorCount();
}
public List getAllErrors() {
public List<ObjectError> getAllErrors() {
return escapeObjectErrors(this.source.getAllErrors());
}
@@ -129,7 +128,7 @@ public class EscapedErrors implements Errors {
return this.source.getGlobalErrorCount();
}
public List getGlobalErrors() {
public List<ObjectError> getGlobalErrors() {
return escapeObjectErrors(this.source.getGlobalErrors());
}
@@ -145,7 +144,7 @@ public class EscapedErrors implements Errors {
return this.source.getFieldErrorCount();
}
public List getFieldErrors() {
public List<FieldError> getFieldErrors() {
return this.source.getFieldErrors();
}
@@ -161,12 +160,12 @@ public class EscapedErrors implements Errors {
return this.source.getFieldErrorCount(field);
}
public List getFieldErrors(String field) {
public List<FieldError> getFieldErrors(String field) {
return escapeObjectErrors(this.source.getFieldErrors(field));
}
public FieldError getFieldError(String field) {
return (FieldError) escapeObjectError(this.source.getFieldError(field));
return escapeObjectError(this.source.getFieldError(field));
}
public Object getFieldValue(String field) {
@@ -178,7 +177,8 @@ public class EscapedErrors implements Errors {
return this.source.getFieldType(field);
}
private ObjectError escapeObjectError(ObjectError source) {
@SuppressWarnings("unchecked")
private <T extends ObjectError> T escapeObjectError(T source) {
if (source == null) {
return null;
}
@@ -188,20 +188,21 @@ public class EscapedErrors implements Errors {
if (value instanceof String) {
value = HtmlUtils.htmlEscape((String) value);
}
return new FieldError(
return (T) new FieldError(
fieldError.getObjectName(), fieldError.getField(), value,
fieldError.isBindingFailure(), fieldError.getCodes(),
fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage()));
}
return new ObjectError(
source.getObjectName(), source.getCodes(), source.getArguments(),
HtmlUtils.htmlEscape(source.getDefaultMessage()));
else {
return (T) new ObjectError(
source.getObjectName(), source.getCodes(), source.getArguments(),
HtmlUtils.htmlEscape(source.getDefaultMessage()));
}
}
private List escapeObjectErrors(List source) {
List escaped = new ArrayList(source.size());
for (Iterator it = source.iterator(); it.hasNext();) {
ObjectError objectError = (ObjectError)it.next();
private <T extends ObjectError> List<T> escapeObjectErrors(List<T> source) {
List<T> escaped = new ArrayList<T>(source.size());
for (T objectError : source) {
escaped.add(escapeObjectError(objectError));
}
return escaped;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -17,6 +17,7 @@
package org.springframework.web.servlet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.util.CollectionUtils;
@@ -35,7 +36,7 @@ public class HandlerExecutionChain {
private HandlerInterceptor[] interceptors;
private List interceptorList;
private List<HandlerInterceptor> interceptorList;
/**
@@ -56,7 +57,7 @@ public class HandlerExecutionChain {
if (handler instanceof HandlerExecutionChain) {
HandlerExecutionChain originalChain = (HandlerExecutionChain) handler;
this.handler = originalChain.getHandler();
this.interceptorList = new ArrayList();
this.interceptorList = new ArrayList<HandlerInterceptor>();
CollectionUtils.mergeArrayIntoCollection(originalChain.getInterceptors(), this.interceptorList);
CollectionUtils.mergeArrayIntoCollection(interceptors, this.interceptorList);
}
@@ -83,20 +84,16 @@ public class HandlerExecutionChain {
public void addInterceptors(HandlerInterceptor[] interceptors) {
if (interceptors != null) {
initInterceptorList();
for (int i = 0; i < interceptors.length; i++) {
this.interceptorList.add(interceptors[i]);
}
this.interceptorList.addAll(Arrays.asList(interceptors));
}
}
private void initInterceptorList() {
if (this.interceptorList == null) {
this.interceptorList = new ArrayList();
this.interceptorList = new ArrayList<HandlerInterceptor>();
}
if (this.interceptors != null) {
for (int i = 0; i < this.interceptors.length; i++) {
this.interceptorList.add(this.interceptors[i]);
}
this.interceptorList.addAll(Arrays.asList(this.interceptors));
this.interceptors = null;
}
}
@@ -107,17 +104,18 @@ public class HandlerExecutionChain {
*/
public HandlerInterceptor[] getInterceptors() {
if (this.interceptors == null && this.interceptorList != null) {
this.interceptors = (HandlerInterceptor[])
this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]);
this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]);
}
return this.interceptors;
}
/**
* Delegates to the handler's <code>toString()</code>.
*/
@Override
public String toString() {
return String.valueOf(handler);
return String.valueOf(this.handler);
}
}

View File

@@ -81,7 +81,7 @@ public abstract class HttpServletBean extends HttpServlet {
* Set of required properties (Strings) that must be supplied as
* config parameters to this servlet.
*/
private final Set requiredProperties = new HashSet();
private final Set<String> requiredProperties = new HashSet<String>();
/**
@@ -187,11 +187,11 @@ public abstract class HttpServletBean extends HttpServlet {
* we can't accept default values
* @throws ServletException if any required properties are missing
*/
public ServletConfigPropertyValues(ServletConfig config, Set requiredProperties)
public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties)
throws ServletException {
Set missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ?
new HashSet(requiredProperties) : null;
Set<String> missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ?
new HashSet<String>(requiredProperties) : null;
Enumeration en = config.getInitParameterNames();
while (en.hasMoreElements()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -52,7 +52,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
private Object defaultHandler;
private final List interceptors = new ArrayList();
private final List<Object> interceptors = new ArrayList<Object>();
private HandlerInterceptor[] adaptedInterceptors;

View File

@@ -55,7 +55,7 @@ public class BeanNameUrlHandlerMapping extends AbstractDetectingUrlHandlerMappin
*/
@Override
protected String[] determineUrlsForHandler(String beanName) {
List urls = new ArrayList();
List<String> urls = new ArrayList<String>();
if (beanName.startsWith("/")) {
urls.add(beanName);
}

View File

@@ -65,7 +65,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
/** Set of supported HTTP methods */
private Set supportedMethods;
private Set<String> supportedMethods;
private boolean requireSession = false;
@@ -97,7 +97,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
*/
public WebContentGenerator(boolean restrictDefaultSupportedMethods) {
if (restrictDefaultSupportedMethods) {
this.supportedMethods = new HashSet(4);
this.supportedMethods = new HashSet<String>(4);
this.supportedMethods.add(METHOD_GET);
this.supportedMethods.add(METHOD_HEAD);
this.supportedMethods.add(METHOD_POST);
@@ -111,7 +111,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
*/
public final void setSupportedMethods(String[] methods) {
if (methods != null) {
this.supportedMethods = new HashSet(Arrays.asList(methods));
this.supportedMethods = new HashSet<String>(Arrays.asList(methods));
}
else {
this.supportedMethods = null;

View File

@@ -19,7 +19,6 @@ package org.springframework.web.servlet.tags.form;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
@@ -169,7 +168,7 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag {
*/
@Override
protected void exposeAttributes() throws JspException {
List errorMessages = new ArrayList();
List<String> errorMessages = new ArrayList<String>();
errorMessages.addAll(Arrays.asList(getBindStatus().getErrorMessages()));
this.oldMessages = this.pageContext.getAttribute(MESSAGES_ATTRIBUTE, PageContext.PAGE_SCOPE);
this.pageContext.setAttribute(MESSAGES_ATTRIBUTE, errorMessages, PageContext.PAGE_SCOPE);

View File

@@ -74,7 +74,7 @@ public class InternalResourceView extends AbstractUrlBasedView {
private boolean exposeContextBeansAsAttributes = false;
private Set exposedContextBeanNames;
private Set<String> exposedContextBeanNames;
private boolean preventDispatchLoop = false;
@@ -158,7 +158,7 @@ public class InternalResourceView extends AbstractUrlBasedView {
* flag on but do not list specific bean names for this property.
*/
public void setExposedContextBeanNames(String[] exposedContextBeanNames) {
this.exposedContextBeanNames = new HashSet(Arrays.asList(exposedContextBeanNames));
this.exposedContextBeanNames = new HashSet<String>(Arrays.asList(exposedContextBeanNames));
}
/**