Polishing

This commit is contained in:
Juergen Hoeller
2014-07-29 10:10:48 +02:00
parent daaeeaa8e2
commit c0a4631fd1
56 changed files with 845 additions and 794 deletions

View File

@@ -1,28 +1,16 @@
/*
* Copyright 2002-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Spring's repackaging of <a href="http://asm.ow2.org">org.objectweb.asm 4</a> (for
* internal use only).
* Spring's repackaging of
* <a href="http://asm.ow2.org">org.objectweb.asm 5.0</a>
* (for internal use only).
*
* <p>This repackaging technique avoids any potential conflicts with
* dependencies on ASM at the application level or from other third-party
* dependencies on ASM at the application level or from third-party
* libraries and frameworks.
* <p>As this repackaging happens at the classfile level, sources and Javadoc
* are not available here. See the original ObjectWeb
* <a href="http://asm.ow2.org/asm40/javadoc/user">ASM 4 Javadoc</a>
*
* <p>As this repackaging happens at the class file level, sources
* and javadocs are not available here. See the original ObjectWeb
* <a href="http://asm.ow2.org/asm50/javadoc/user">ASM 5.0 javadocs</a>
* for details when working with these classes.
*
* @since 3.2

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -62,6 +62,7 @@ public final class Property {
private Annotation[] annotations;
public Property(Class<?> objectType, Method readMethod, Method writeMethod) {
this(objectType, readMethod, writeMethod, null);
}
@@ -118,7 +119,7 @@ public final class Property {
}
Annotation[] getAnnotations() {
if(this.annotations == null) {
if (this.annotations == null) {
this.annotations = resolveAnnotations();
}
return this.annotations;
@@ -192,7 +193,7 @@ public final class Property {
private Annotation[] resolveAnnotations() {
Annotation[] annotations = annotationCache.get(this);
if(annotations == null) {
if (annotations == null) {
Map<Class<? extends Annotation>, Annotation> annotationMap = new LinkedHashMap<Class<? extends Annotation>, Annotation>();
addAnnotationsToMap(annotationMap, getReadMethod());
addAnnotationsToMap(annotationMap, getWriteMethod());
@@ -241,34 +242,25 @@ public final class Property {
}
}
@Override
public int hashCode() {
final int prime = 31;
int hashCode = 1;
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(objectType);
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(readMethod);
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(writeMethod);
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(name);
return hashCode;
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof Property)) {
return false;
}
Property otherProperty = (Property) other;
return (ObjectUtils.nullSafeEquals(this.objectType, otherProperty.objectType) &&
ObjectUtils.nullSafeEquals(this.name, otherProperty.name) &&
ObjectUtils.nullSafeEquals(this.readMethod, otherProperty.readMethod) &&
ObjectUtils.nullSafeEquals(this.writeMethod, otherProperty.writeMethod));
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Property other = (Property) obj;
boolean equals = true;
equals &= ObjectUtils.nullSafeEquals(objectType, other.objectType);
equals &= ObjectUtils.nullSafeEquals(readMethod, other.readMethod);
equals &= ObjectUtils.nullSafeEquals(writeMethod, other.writeMethod);
equals &= ObjectUtils.nullSafeEquals(name, other.name);
return equals;
public int hashCode() {
return (ObjectUtils.nullSafeHashCode(this.objectType) * 31 + ObjectUtils.nullSafeHashCode(this.name));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -40,11 +40,13 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
private final ConversionService conversionService;
public ArrayToArrayConverter(ConversionService conversionService) {
this.helperConverter = new CollectionToArrayConverter(conversionService);
this.conversionService = conversionService;
}
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object[].class, Object[].class));
}
@@ -53,12 +55,10 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
return this.helperConverter.matches(sourceType, targetType);
}
public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
if ((conversionService instanceof GenericConversionService)
&& ((GenericConversionService) conversionService).canBypassConvert(
sourceType.getElementTypeDescriptor(),
targetType.getElementTypeDescriptor())) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (this.conversionService instanceof GenericConversionService &&
((GenericConversionService) this.conversionService).canBypassConvert(
sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor())) {
return source;
}
List<Object> sourceList = Arrays.asList(ObjectUtils.toObjectArray(source));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2014 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.
@@ -27,7 +27,8 @@ import org.springframework.util.ObjectUtils;
/**
* Converts an Array to a comma-delimited String.
* This implementation first adapts the source Array to a List, then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
* This implementation first adapts the source Array to a List,
* then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
*
* @author Keith Donald
* @since 3.0
@@ -36,10 +37,12 @@ final class ArrayToStringConverter implements ConditionalGenericConverter {
private final CollectionToStringConverter helperConverter;
public ArrayToStringConverter(ConversionService conversionService) {
this.helperConverter = new CollectionToStringConverter(conversionService);
}
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object[].class, String.class));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -42,10 +42,12 @@ final class MapToMapConverter implements ConditionalGenericConverter {
private final ConversionService conversionService;
public MapToMapConverter(ConversionService conversionService) {
this.conversionService = conversionService;
}
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Map.class, Map.class));
}
@@ -75,7 +77,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
copyRequired = true;
}
}
if(!copyRequired) {
if (!copyRequired) {
return sourceMap;
}
Map<Object, Object> targetMap = CollectionFactory.createMap(targetType.getType(), sourceMap.size());
@@ -85,6 +87,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
return targetMap;
}
// internal helpers
private boolean canConvertKey(TypeDescriptor sourceType, TypeDescriptor targetType) {
@@ -111,10 +114,12 @@ final class MapToMapConverter implements ConditionalGenericConverter {
return this.conversionService.convert(sourceValue, sourceType.getMapValueTypeDescriptor(sourceValue), targetType);
}
private static class MapEntry {
private Object key;
private Object value;
private final Object key;
private final Object value;
public MapEntry(Object key, Object value) {
this.key = key;
@@ -122,7 +127,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
}
public void addToMap(Map<Object, Object> map) {
map.put(key, value);
map.put(this.key, this.value);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
@@ -28,7 +28,8 @@ import org.springframework.util.StringUtils;
/**
* Converts a comma-delimited String to a Collection.
* If the target collection element type is declared, only matches if String.class can be converted to it.
* If the target collection element type is declared, only matches if
* {@code String.class} can be converted to it.
*
* @author Keith Donald
* @since 3.0
@@ -37,20 +38,19 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
private final ConversionService conversionService;
public StringToCollectionConverter(ConversionService conversionService) {
this.conversionService = conversionService;
}
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(String.class, Collection.class));
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
if (targetType.getElementTypeDescriptor() != null) {
return this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor());
} else {
return true;
}
return (targetType.getElementTypeDescriptor() == null ||
this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor()));
}
@SuppressWarnings("unchecked")
@@ -65,7 +65,8 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
for (String field : fields) {
target.add(field.trim());
}
} else {
}
else {
for (String field : fields) {
Object targetElement = this.conversionService.convert(field.trim(), sourceType, targetType.getElementTypeDescriptor());
target.add(targetElement);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.core.convert.support;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.util.Assert;
/**
* Converts from a String to a java.lang.Enum by calling {@link Enum#valueOf(Class, String)}.
@@ -31,14 +30,16 @@ final class StringToEnumConverterFactory implements ConverterFactory<String, Enu
public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
Class<?> enumType = targetType;
while(enumType != null && !enumType.isEnum()) {
while (enumType != null && !enumType.isEnum()) {
enumType = enumType.getSuperclass();
}
Assert.notNull(enumType, "The target type " + targetType.getName()
+ " does not refer to an enum");
if (enumType == null) {
throw new IllegalArgumentException("The target type " + targetType.getName() + " does not refer to an enum");
}
return new StringToEnum(enumType);
}
private class StringToEnum<T extends Enum> implements Converter<String, T> {
private final Class<T> enumType;

View File

@@ -30,7 +30,7 @@ import org.springframework.util.StringUtils;
final class StringToUUIDConverter implements Converter<String, UUID> {
public UUID convert(String source) {
if(StringUtils.hasLength(source)) {
if (StringUtils.hasLength(source)) {
return UUID.fromString(source.trim());
}
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -122,7 +122,7 @@ public abstract class AbstractResource implements Resource {
long size = 0;
byte[] buf = new byte[255];
int read;
while((read = is.read(buf)) != -1) {
while ((read = is.read(buf)) != -1) {
size += read;
}
return size;

View File

@@ -155,7 +155,7 @@ public abstract class ObjectUtils {
*/
public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, String constant) {
for (E candidate : enumValues) {
if(candidate.toString().equalsIgnoreCase(constant)) {
if (candidate.toString().equalsIgnoreCase(constant)) {
return candidate;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -229,7 +229,8 @@ public class StopWatch {
sb.append('\n');
if (!this.keepTaskList) {
sb.append("No task info kept");
} else {
}
else {
sb.append("-----------------------------------------\n");
sb.append("ms % Task name\n");
sb.append("-----------------------------------------\n");
@@ -261,7 +262,8 @@ public class StopWatch {
long percent = Math.round((100.0 * task.getTimeSeconds()) / getTotalTimeSeconds());
sb.append(" = ").append(percent).append("%");
}
} else {
}
else {
sb.append("; no task info kept");
}
return sb.toString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -31,23 +31,22 @@ import org.springframework.util.Assert;
* is required.
*
* @author Phillip Webb
* @param <T> The type of objects being compared
* @see CompoundComparator
* @since 3.2
* @param <T> the type of objects being compared
* @see CompoundComparator
*/
public class InstanceComparator<T> implements Comparator<T> {
private Class<?>[] instanceOrder;
private final Class<?>[] instanceOrder;
/**
* Create a new {@link InstanceComparator} instance.
*
* @param instanceOrder the ordered list of classes that should be used when comparing
* objects. Classes earlier in the list will be be given a higher priority.
*/
public InstanceComparator(Class<?>... instanceOrder) {
Assert.notNull(instanceOrder, "InstanceOrder must not be null");
Assert.notNull(instanceOrder, "'instanceOrder' must not be null");
this.instanceOrder = instanceOrder;
}
@@ -59,14 +58,14 @@ public class InstanceComparator<T> implements Comparator<T> {
}
private int getOrder(T object) {
if(object != null) {
for (int i = 0; i < instanceOrder.length; i++) {
if (instanceOrder[i].isInstance(object)) {
if (object != null) {
for (int i = 0; i < this.instanceOrder.length; i++) {
if (this.instanceOrder[i].isInstance(object)) {
return i;
}
}
}
return instanceOrder.length;
return this.instanceOrder.length;
}
}
}

View File

@@ -1,3 +1,4 @@
/**
*
* Useful generic {@code java.util.Comparator} implementations,