From ae35e84c1eb40d97909b7d9d6b79075a72e87235 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 May 2015 17:27:41 +0200 Subject: [PATCH] Polishing (cherry picked from commit 0711d6d) --- .../beans/TypeConverterDelegate.java | 5 ++--- .../support/FormattingConversionService.java | 18 +++++++++--------- .../springframework/validation/DataBinder.java | 3 ++- .../support/StringToLocaleConverter.java | 5 +++-- .../convert/support/StringToUUIDConverter.java | 10 ++++------ .../resource/ResourceUrlEncodingFilter.java | 9 ++++----- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java index 513393bd7c..c3c12ab307 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -204,7 +204,7 @@ class TypeConverterDelegate { if (Object.class.equals(requiredType)) { return (T) convertedValue; } - if (requiredType.isArray()) { + else if (requiredType.isArray()) { // Array required -> apply appropriate conversion of elements. if (convertedValue instanceof String && Enum.class.isAssignableFrom(requiredType.getComponentType())) { convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue); @@ -339,7 +339,6 @@ class TypeConverterDelegate { catch (Throwable ex) { if (logger.isTraceEnabled()) { logger.trace("Field [" + convertedValue + "] isn't an enum value", ex); - } } } diff --git a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java index 3ddf7e6143..7762dd6757 100644 --- a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java +++ b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -88,8 +88,8 @@ public class FormattingConversionService extends GenericConversionService } @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) - public void addFormatterForFieldAnnotation(AnnotationFormatterFactory annotationFormatterFactory) { + @SuppressWarnings("unchecked") + public void addFormatterForFieldAnnotation(AnnotationFormatterFactory annotationFormatterFactory) { Class annotationType = (Class) GenericTypeResolver.resolveTypeArgument(annotationFormatterFactory.getClass(), AnnotationFormatterFactory.class); if (annotationType == null) { @@ -148,7 +148,7 @@ public class FormattingConversionService extends GenericConversionService @Override public String toString() { - return this.fieldType.getName() + " -> " + String.class.getName() + " : " + this.printer; + return (this.fieldType.getName() + " -> " + String.class.getName() + " : " + this.printer); } } @@ -197,7 +197,7 @@ public class FormattingConversionService extends GenericConversionService @Override public String toString() { - return String.class.getName() + " -> " + this.fieldType.getName() + ": " + this.parser; + return (String.class.getName() + " -> " + this.fieldType.getName() + ": " + this.parser); } } @@ -249,8 +249,8 @@ public class FormattingConversionService extends GenericConversionService @Override public String toString() { - return "@" + this.annotationType.getName() + " " + this.fieldType.getName() + " -> " + - String.class.getName() + ": " + this.annotationFormatterFactory; + return ("@" + this.annotationType.getName() + " " + this.fieldType.getName() + " -> " + + String.class.getName() + ": " + this.annotationFormatterFactory); } } @@ -302,8 +302,8 @@ public class FormattingConversionService extends GenericConversionService @Override public String toString() { - return String.class.getName() + " -> @" + this.annotationType.getName() + " " + - this.fieldType.getName() + ": " + this.annotationFormatterFactory; + return (String.class.getName() + " -> @" + this.annotationType.getName() + " " + + this.fieldType.getName() + ": " + this.annotationFormatterFactory); } } diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java index 6c19ce712f..73b1753836 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -553,6 +553,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { return Collections.unmodifiableList(this.validators); } + //--------------------------------------------------------------------- // Implementation of PropertyEditorRegistry/TypeConverter interface //--------------------------------------------------------------------- diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToLocaleConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToLocaleConverter.java index c6c22ea280..f4b6f53802 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToLocaleConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToLocaleConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -22,10 +22,11 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.util.StringUtils; /** - * Converts a String to a Locale. + * Converts from a String to a {@link java.util.Locale}. * * @author Keith Donald * @since 3.0 + * @see StringUtils#parseLocaleString */ final class StringToLocaleConverter implements Converter { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java index 48e6a0aef2..364108547c 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -22,19 +22,17 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.util.StringUtils; /** - * Converts from a String to a java.util.UUID by calling {@link UUID#fromString(String)}. + * Converts from a String to a {@link java.util.UUID}. * * @author Phillip Webb * @since 3.2 + * @see UUID#fromString */ final class StringToUUIDConverter implements Converter { @Override public UUID convert(String source) { - if (StringUtils.hasLength(source)) { - return UUID.fromString(source.trim()); - } - return null; + return (StringUtils.hasLength(source) ? UUID.fromString(source.trim()) : null); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index 4984529692..9a05345099 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -59,8 +59,7 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter { /* Cache the index of the path within the DispatcherServlet mapping. */ private Integer indexLookupPath; - - private ResourceUrlEncodingResponseWrapper(HttpServletRequest request, HttpServletResponse wrapped) { + public ResourceUrlEncodingResponseWrapper(HttpServletRequest request, HttpServletResponse wrapped) { super(wrapped); this.request = request; } @@ -69,11 +68,11 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter { public String encodeURL(String url) { ResourceUrlProvider resourceUrlProvider = getResourceUrlProvider(); if (resourceUrlProvider == null) { - logger.debug("Request attribute exposing ResourceUrlProvider not found."); + logger.debug("Request attribute exposing ResourceUrlProvider not found"); return super.encodeURL(url); } initIndexLookupPath(resourceUrlProvider); - if(url.length() >= this.indexLookupPath) { + if (url.length() >= this.indexLookupPath) { String prefix = url.substring(0, this.indexLookupPath); String lookupPath = url.substring(this.indexLookupPath); lookupPath = resourceUrlProvider.getForLookupPath(lookupPath);