EL container integration; support for contextual objects; removal of deprecated Spring 2.0 functionality; Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-20 02:10:53 +00:00
parent 369821dd66
commit 347f34c68a
281 changed files with 6120 additions and 9903 deletions

View File

@@ -50,10 +50,7 @@ import org.springframework.util.ClassUtils;
*
* <p>The goal of this class is to avoid runtime dependencies on JDK 1.5+ and
* Commons Collections 3.x, simply using the best collection implementation
* that is available at runtime. As of Spring 2.5, JDK 1.4 is required,
* so former adapter methods for JDK 1.3/1.4 always return the JDK 1.4
* collections now. The adapter methods are still kept for supporting
* Spring-based applications/frameworks which were built to support JDK 1.3.
* that is available at runtime.
*
* @author Juergen Hoeller
* @author Arjen Poutsma
@@ -167,7 +164,7 @@ public abstract class CollectionFactory {
/**
* Create a concurrent Map if possible: This implementation always
* creates a {@link java.util.concurrent.ConcurrentHashMap}, since Spring 3.0
* required JDK 1.5 anyway.
* requires JDK 1.5 anyway.
* @param initialCapacity the initial capacity of the Map
* @return the new Map instance
* @deprecated as of Spring 3.0, for usage on JDK 1.5 or higher
@@ -180,7 +177,7 @@ public abstract class CollectionFactory {
/**
* Create a concurrent Map with a dedicated {@link ConcurrentMap} interface:
* This implementation always creates a {@link java.util.concurrent.ConcurrentHashMap},
* since Spring 3.0 required JDK 1.5 anyway.
* since Spring 3.0 requires JDK 1.5 anyway.
* @param initialCapacity the initial capacity of the Map
* @return the new ConcurrentMap instance
* @deprecated as of Spring 3.0, for usage on JDK 1.5 or higher

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.
@@ -329,7 +329,7 @@ public class Constants {
* @see #toCodeForProperty
*/
public String propertyToConstantNamePrefix(String propertyName) {
StringBuffer parsedPrefix = new StringBuffer();
StringBuilder parsedPrefix = new StringBuilder();
for(int i = 0; i < propertyName.length(); i++) {
char c = propertyName.charAt(i);
if (Character.isUpperCase(c)) {

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.
@@ -105,7 +105,7 @@ public abstract class ControlFlowFactory {
@Override
public String toString() {
StringBuffer sb = new StringBuffer("Jdk14ControlFlow: ");
StringBuilder sb = new StringBuilder("Jdk14ControlFlow: ");
for (int i = 0; i < this.stack.length; i++) {
if (i > 0) {
sb.append("\n\t@");

View File

@@ -115,11 +115,10 @@ public abstract class Conventions {
pluralize = true;
}
else if (Collection.class.isAssignableFrom(parameter.getParameterType())) {
if (JdkVersion.isAtLeastJava15()) {
valueClass = GenericCollectionTypeResolver.getCollectionParameterType(parameter);
}
valueClass = GenericCollectionTypeResolver.getCollectionParameterType(parameter);
if (valueClass == null) {
throw new IllegalArgumentException("Cannot generate variable name for non-typed Collection parameter type");
throw new IllegalArgumentException(
"Cannot generate variable name for non-typed Collection parameter type");
}
pluralize = true;
}
@@ -182,9 +181,7 @@ public abstract class Conventions {
pluralize = true;
}
else if (Collection.class.isAssignableFrom(resolvedType)) {
if (JdkVersion.isAtLeastJava15()) {
valueClass = GenericCollectionTypeResolver.getCollectionReturnType(method);
}
valueClass = GenericCollectionTypeResolver.getCollectionReturnType(method);
if (valueClass == null) {
if (!(value instanceof Collection)) {
throw new IllegalArgumentException(

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.
@@ -68,12 +68,9 @@ public abstract class JdkVersion {
else if (javaVersion.indexOf("1.6.") != -1) {
majorJavaVersion = JAVA_16;
}
else if (javaVersion.indexOf("1.5.") != -1) {
majorJavaVersion = JAVA_15;
}
else {
// else leave 1.4 as default (it's either 1.4 or unknown)
majorJavaVersion = JAVA_14;
// else leave 1.5 as default (it's either 1.5 or unknown)
majorJavaVersion = JAVA_15;
}
}
@@ -105,12 +102,14 @@ public abstract class JdkVersion {
/**
* Convenience method to determine if the current JVM is at least Java 1.4.
* @return <code>true</code> if the current JVM is at least Java 1.4
* @deprecated as of Spring 3.0 which requires Java 1.5+
* @see #getMajorJavaVersion()
* @see #JAVA_14
* @see #JAVA_15
* @see #JAVA_16
* @see #JAVA_17
*/
@Deprecated
public static boolean isAtLeastJava14() {
return true;
}
@@ -119,13 +118,15 @@ public abstract class JdkVersion {
* Convenience method to determine if the current JVM is at least
* Java 1.5 (Java 5).
* @return <code>true</code> if the current JVM is at least Java 1.5
* @deprecated as of Spring 3.0 which requires Java 1.5+
* @see #getMajorJavaVersion()
* @see #JAVA_15
* @see #JAVA_16
* @see #JAVA_17
*/
@Deprecated
public static boolean isAtLeastJava15() {
return getMajorJavaVersion() >= JAVA_15;
return true;
}
/**

View File

@@ -20,10 +20,12 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -54,13 +56,13 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
private static Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class);
private final Map parameterNamesCache = CollectionFactory.createConcurrentMapIfPossible(16);
private final Map<Member, String[]> parameterNamesCache = new ConcurrentHashMap<Member, String[]>();
private final Map classReaderCache = new HashMap();
private final Map<Class, ClassReader> classReaderCache = new HashMap<Class, ClassReader>();
public String[] getParameterNames(Method method) {
String[] paramNames = (String[]) this.parameterNamesCache.get(method);
String[] paramNames = this.parameterNamesCache.get(method);
if (paramNames == null) {
try {
paramNames = visitMethod(method).getParameterNames();
@@ -82,7 +84,7 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
}
public String[] getParameterNames(Constructor ctor) {
String[] paramNames = (String[]) this.parameterNamesCache.get(ctor);
String[] paramNames = this.parameterNamesCache.get(ctor);
if (paramNames == null) {
try {
paramNames = visitConstructor(ctor).getParameterNames();

View File

@@ -16,14 +16,13 @@
package org.springframework.core;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
/**
* Helper class that encapsulates the specification of a method parameter, i.e.
@@ -34,10 +33,6 @@ import org.springframework.util.ReflectionUtils;
* {@link org.springframework.beans.BeanWrapperImpl} and
* {@link org.springframework.beans.factory.support.AbstractBeanFactory}.
*
* <p>Note that this class does not depend on JDK 1.5 API artifacts, in order
* to remain compatible with JDK 1.4. Concrete generic type resolution
* via JDK 1.5 API happens in {@link GenericCollectionTypeResolver} only.
*
* @author Juergen Hoeller
* @author Rob Harrop
* @since 2.0
@@ -45,13 +40,6 @@ import org.springframework.util.ReflectionUtils;
*/
public class MethodParameter {
private static final Method methodParameterAnnotationsMethod =
ClassUtils.getMethodIfAvailable(Method.class, "getParameterAnnotations", new Class[0]);
private static final Method constructorParameterAnnotationsMethod =
ClassUtils.getMethodIfAvailable(Constructor.class, "getParameterAnnotations", new Class[0]);
private Method method;
private Constructor constructor;
@@ -60,7 +48,7 @@ public class MethodParameter {
private Class parameterType;
private Object[] parameterAnnotations;
private Annotation[] parameterAnnotations;
private ParameterNameDiscoverer parameterNameDiscoverer;
@@ -69,7 +57,7 @@ public class MethodParameter {
private int nestingLevel = 1;
/** Map from Integer level to Integer type index */
private Map typeIndexesPerLevel;
private Map<Integer,Integer> typeIndexesPerLevel;
Map typeVariableMap;
@@ -188,22 +176,13 @@ public class MethodParameter {
/**
* Return the annotations associated with the method/constructor parameter.
* @return the parameter annotations, or <code>null</code> if there is
* no annotation support (on JDK < 1.5). The return value is an Object array
* instead of an Annotation array simply for compatibility with older JDKs;
* feel free to cast it to <code>Annotation[]</code> on JDK 1.5 or higher.
*/
public Object[] getParameterAnnotations() {
if (this.parameterAnnotations != null) {
return this.parameterAnnotations;
public Annotation[] getParameterAnnotations() {
if (this.parameterAnnotations == null) {
Annotation[][] annotationArray = (this.method != null) ?
this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations();
this.parameterAnnotations = annotationArray[this.parameterIndex];
}
if (methodParameterAnnotationsMethod == null) {
return null;
}
Object[][] annotationArray = (this.method != null ?
((Object[][]) ReflectionUtils.invokeMethod(methodParameterAnnotationsMethod, this.method)) :
((Object[][]) ReflectionUtils.invokeMethod(constructorParameterAnnotationsMethod, this.constructor)));
this.parameterAnnotations = annotationArray[this.parameterIndex];
return this.parameterAnnotations;
}
@@ -250,7 +229,7 @@ public class MethodParameter {
* @see #getNestingLevel()
*/
public void decreaseNestingLevel() {
getTypeIndexesPerLevel().remove(new Integer(this.nestingLevel));
getTypeIndexesPerLevel().remove(this.nestingLevel);
this.nestingLevel--;
}
@@ -270,7 +249,7 @@ public class MethodParameter {
* @see #getNestingLevel()
*/
public void setTypeIndexForCurrentLevel(int typeIndex) {
getTypeIndexesPerLevel().put(new Integer(this.nestingLevel), new Integer(typeIndex));
getTypeIndexesPerLevel().put(this.nestingLevel, typeIndex);
}
/**
@@ -290,15 +269,15 @@ public class MethodParameter {
* if none specified (indicating the default type index)
*/
public Integer getTypeIndexForLevel(int nestingLevel) {
return (Integer) getTypeIndexesPerLevel().get(new Integer(nestingLevel));
return getTypeIndexesPerLevel().get(nestingLevel);
}
/**
* Obtain the (lazily constructed) type-indexes-per-level Map.
*/
private Map getTypeIndexesPerLevel() {
private Map<Integer, Integer> getTypeIndexesPerLevel() {
if (this.typeIndexesPerLevel == null) {
this.typeIndexesPerLevel = new HashMap(4);
this.typeIndexesPerLevel = new HashMap<Integer, Integer>(4);
}
return this.typeIndexesPerLevel;
}

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.
@@ -40,12 +40,12 @@ public abstract class NestedExceptionUtils {
*/
public static String buildMessage(String message, Throwable cause) {
if (cause != null) {
StringBuffer buf = new StringBuffer();
StringBuilder sb = new StringBuilder();
if (message != null) {
buf.append(message).append("; ");
sb.append(message).append("; ");
}
buf.append("nested exception is ").append(cause);
return buf.toString();
sb.append("nested exception is ").append(cause);
return sb.toString();
}
else {
return message;

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.
@@ -32,7 +32,7 @@ import java.util.Comparator;
* @see java.util.Collections#sort(java.util.List, java.util.Comparator)
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
*/
public class OrderComparator implements Comparator {
public class OrderComparator implements Comparator<Object> {
public int compare(Object o1, Object o2) {
boolean p1 = (o1 instanceof PriorityOrdered);

View File

@@ -18,9 +18,9 @@ package org.springframework.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -38,7 +38,7 @@ import org.springframework.util.StringValueResolver;
public class SimpleAliasRegistry implements AliasRegistry {
/** Map from alias to canonical name */
private final Map aliasMap = CollectionFactory.createConcurrentMapIfPossible(16);
private final Map<String, String> aliasMap = new ConcurrentHashMap<String, String>();
public void registerAlias(String name, String alias) {
@@ -49,7 +49,7 @@ public class SimpleAliasRegistry implements AliasRegistry {
}
else {
if (!allowAliasOverriding()) {
String registeredName = (String) this.aliasMap.get(alias);
String registeredName = this.aliasMap.get(alias);
if (registeredName != null && !registeredName.equals(name)) {
throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" +
name + "': It is already registered for name '" + registeredName + "'.");
@@ -68,7 +68,7 @@ public class SimpleAliasRegistry implements AliasRegistry {
}
public void removeAlias(String alias) {
String name = (String) this.aliasMap.remove(alias);
String name = this.aliasMap.remove(alias);
if (name == null) {
throw new IllegalStateException("No alias '" + alias + "' registered");
}
@@ -79,11 +79,10 @@ public class SimpleAliasRegistry implements AliasRegistry {
}
public String[] getAliases(String name) {
List aliases = new ArrayList();
List<String> aliases = new ArrayList<String>();
synchronized (this.aliasMap) {
for (Iterator it = this.aliasMap.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String registeredName = (String) entry.getValue();
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) {
String registeredName = entry.getValue();
if (registeredName.equals(name)) {
aliases.add(entry.getKey());
}
@@ -102,18 +101,18 @@ public class SimpleAliasRegistry implements AliasRegistry {
public void resolveAliases(StringValueResolver valueResolver) {
Assert.notNull(valueResolver, "StringValueResolver must not be null");
synchronized (this.aliasMap) {
Map aliasCopy = new HashMap(this.aliasMap);
for (Iterator it = aliasCopy.keySet().iterator(); it.hasNext();) {
String alias = (String) it.next();
String registeredName = (String) aliasCopy.get(alias);
Map<String, String> aliasCopy = new HashMap<String, String>(this.aliasMap);
for (String alias : aliasCopy.keySet()) {
String registeredName = aliasCopy.get(alias);
String resolvedAlias = valueResolver.resolveStringValue(alias);
String resolvedName = valueResolver.resolveStringValue(registeredName);
if (!resolvedAlias.equals(alias)) {
String existingName = (String) this.aliasMap.get(resolvedAlias);
String existingName = this.aliasMap.get(resolvedAlias);
if (existingName != null && !existingName.equals(resolvedName)) {
throw new IllegalStateException("Cannot register resolved alias '" +
resolvedAlias + "' (original: '" + alias + "') for name '" + resolvedName +
"': It is already registered for name '" + registeredName + "'.");
throw new IllegalStateException(
"Cannot register resolved alias '" + resolvedAlias + "' (original: '" + alias +
"') for name '" + resolvedName + "': It is already registered for name '" +
registeredName + "'.");
}
this.aliasMap.put(resolvedAlias, resolvedName);
this.aliasMap.remove(alias);
@@ -135,7 +134,7 @@ public class SimpleAliasRegistry implements AliasRegistry {
// Handle aliasing.
String resolvedName = null;
do {
resolvedName = (String) this.aliasMap.get(canonicalName);
resolvedName = this.aliasMap.get(canonicalName);
if (resolvedName != null) {
canonicalName = resolvedName;
}

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 class DefaultToStringStyler implements ToStringStyler {
}
public void styleStart(StringBuffer buffer, Object obj) {
public void styleStart(StringBuilder buffer, Object obj) {
if (!obj.getClass().isArray()) {
buffer.append('[').append(ClassUtils.getShortName(obj.getClass()));
styleIdentityHashCode(buffer, obj);
@@ -65,33 +65,33 @@ public class DefaultToStringStyler implements ToStringStyler {
}
}
private void styleIdentityHashCode(StringBuffer buffer, Object obj) {
private void styleIdentityHashCode(StringBuilder buffer, Object obj) {
buffer.append('@');
buffer.append(ObjectUtils.getIdentityHexString(obj));
}
public void styleEnd(StringBuffer buffer, Object o) {
public void styleEnd(StringBuilder buffer, Object o) {
buffer.append(']');
}
public void styleField(StringBuffer buffer, String fieldName, Object value) {
public void styleField(StringBuilder buffer, String fieldName, Object value) {
styleFieldStart(buffer, fieldName);
styleValue(buffer, value);
styleFieldEnd(buffer, fieldName);
}
protected void styleFieldStart(StringBuffer buffer, String fieldName) {
protected void styleFieldStart(StringBuilder buffer, String fieldName) {
buffer.append(' ').append(fieldName).append(" = ");
}
protected void styleFieldEnd(StringBuffer buffer, String fieldName) {
protected void styleFieldEnd(StringBuilder buffer, String fieldName) {
}
public void styleValue(StringBuffer buffer, Object value) {
public void styleValue(StringBuilder buffer, Object value) {
buffer.append(this.valueStyler.style(value));
}
public void styleFieldSeparator(StringBuffer buffer) {
public void styleFieldSeparator(StringBuilder buffer) {
buffer.append(',');
}

View File

@@ -80,20 +80,20 @@ public class DefaultValueStyler implements ValueStyler {
}
private String style(Map value) {
StringBuffer buffer = new StringBuffer(value.size() * 8 + 16);
buffer.append(MAP + "[");
StringBuilder result = new StringBuilder(value.size() * 8 + 16);
result.append(MAP + "[");
for (Iterator it = value.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
buffer.append(style(entry));
result.append(style(entry));
if (it.hasNext()) {
buffer.append(',').append(' ');
result.append(',').append(' ');
}
}
if (value.isEmpty()) {
buffer.append(EMPTY);
result.append(EMPTY);
}
buffer.append("]");
return buffer.toString();
result.append("]");
return result.toString();
}
private String style(Map.Entry value) {
@@ -101,19 +101,19 @@ public class DefaultValueStyler implements ValueStyler {
}
private String style(Collection value) {
StringBuffer buffer = new StringBuffer(value.size() * 8 + 16);
buffer.append(getCollectionTypeString(value)).append('[');
StringBuilder result = new StringBuilder(value.size() * 8 + 16);
result.append(getCollectionTypeString(value)).append('[');
for (Iterator i = value.iterator(); i.hasNext();) {
buffer.append(style(i.next()));
result.append(style(i.next()));
if (i.hasNext()) {
buffer.append(',').append(' ');
result.append(',').append(' ');
}
}
if (value.isEmpty()) {
buffer.append(EMPTY);
result.append(EMPTY);
}
buffer.append("]");
return buffer.toString();
result.append("]");
return result.toString();
}
private String getCollectionTypeString(Collection value) {
@@ -129,20 +129,20 @@ public class DefaultValueStyler implements ValueStyler {
}
private String styleArray(Object[] array) {
StringBuffer buffer = new StringBuffer(array.length * 8 + 16);
buffer.append(ARRAY + "<" + ClassUtils.getShortName(array.getClass().getComponentType()) + ">[");
StringBuilder result = new StringBuilder(array.length * 8 + 16);
result.append(ARRAY + "<" + ClassUtils.getShortName(array.getClass().getComponentType()) + ">[");
for (int i = 0; i < array.length - 1; i++) {
buffer.append(style(array[i]));
buffer.append(',').append(' ');
result.append(style(array[i]));
result.append(',').append(' ');
}
if (array.length > 0) {
buffer.append(style(array[array.length - 1]));
result.append(style(array[array.length - 1]));
}
else {
buffer.append(EMPTY);
result.append(EMPTY);
}
buffer.append("]");
return buffer.toString();
result.append("]");
return result.toString();
}
}

View File

@@ -36,7 +36,7 @@ public class ToStringCreator {
new DefaultToStringStyler(StylerUtils.DEFAULT_VALUE_STYLER);
private StringBuffer buffer = new StringBuffer(512);
private StringBuilder buffer = new StringBuilder(512);
private ToStringStyler styler;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2005 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.
@@ -31,14 +31,14 @@ public interface ToStringStyler {
* @param buffer the buffer to print to
* @param obj the object to style
*/
void styleStart(StringBuffer buffer, Object obj);
void styleStart(StringBuilder buffer, Object obj);
/**
* Style a <code>toString()</code>'ed object after it's fields are styled.
* @param buffer the buffer to print to
* @param obj the object to style
*/
void styleEnd(StringBuffer buffer, Object obj);
void styleEnd(StringBuilder buffer, Object obj);
/**
* Style a field value as a string.
@@ -46,19 +46,19 @@ public interface ToStringStyler {
* @param fieldName the he name of the field
* @param value the field value
*/
void styleField(StringBuffer buffer, String fieldName, Object value);
void styleField(StringBuilder buffer, String fieldName, Object value);
/**
* Style the given value.
* @param buffer the buffer to print to
* @param value the field value
*/
void styleValue(StringBuffer buffer, Object value);
void styleValue(StringBuilder buffer, Object value);
/**
* Style the field separator.
* @param buffer buffer to print to
*/
void styleFieldSeparator(StringBuffer buffer);
void styleFieldSeparator(StringBuilder buffer);
}

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.
@@ -19,7 +19,6 @@ package org.springframework.core.task;
import java.io.Serializable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrencyThrottleSupport;
import org.springframework.util.CustomizableThreadCreator;
@@ -44,15 +43,6 @@ import org.springframework.util.CustomizableThreadCreator;
*/
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator implements AsyncTaskExecutor, Serializable {
/**
* Default thread name prefix: "SimpleAsyncTaskExecutor-".
* @deprecated as of Spring 2.0.3, since the default thread name prefix
* is now taken from the concrete class (could be a subclass)
*/
@Deprecated
public static final String DEFAULT_THREAD_NAME_PREFIX =
ClassUtils.getShortName(SimpleAsyncTaskExecutor.class) + "-";
/**
* Permit any number of concurrent invocations: that is, don't throttle concurrency.
*/

View File

@@ -71,13 +71,13 @@ public abstract class ClassUtils {
* Map with primitive wrapper type as key and corresponding primitive
* type as value, for example: Integer.class -> int.class.
*/
private static final Map primitiveWrapperTypeMap = new HashMap(8);
private static final Map<Class, Class> primitiveWrapperTypeMap = new HashMap<Class, Class>(8);
/**
* Map with primitive type name as key and corresponding primitive
* type as value, for example: "int" -> "int.class".
*/
private static final Map primitiveTypeNameMap = new HashMap(16);
private static final Map<String, Class> primitiveTypeNameMap = new HashMap<String, Class>(16);
static {
@@ -90,14 +90,13 @@ public abstract class ClassUtils {
primitiveWrapperTypeMap.put(Long.class, long.class);
primitiveWrapperTypeMap.put(Short.class, short.class);
Set primitiveTypeNames = new HashSet(16);
primitiveTypeNames.addAll(primitiveWrapperTypeMap.values());
primitiveTypeNames.addAll(Arrays.asList(new Class[] {
Set<Class> primitiveTypes = new HashSet<Class>(16);
primitiveTypes.addAll(primitiveWrapperTypeMap.values());
primitiveTypes.addAll(Arrays.asList(
boolean[].class, byte[].class, char[].class, double[].class,
float[].class, int[].class, long[].class, short[].class}));
for (Iterator it = primitiveTypeNames.iterator(); it.hasNext();) {
Class primitiveClass = (Class) it.next();
primitiveTypeNameMap.put(primitiveClass.getName(), primitiveClass);
float[].class, int[].class, long[].class, short[].class));
for (Class primitiveType : primitiveTypes) {
primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);
}
}
@@ -230,15 +229,11 @@ public abstract class ClassUtils {
return forName(className, classLoader);
}
catch (ClassNotFoundException ex) {
IllegalArgumentException iae = new IllegalArgumentException("Cannot find class [" + className + "]");
iae.initCause(ex);
throw iae;
throw new IllegalArgumentException("Cannot find class [" + className + "]", ex);
}
catch (LinkageError ex) {
IllegalArgumentException iae = new IllegalArgumentException(
"Error loading class [" + className + "]: problem with class file or dependent class.");
iae.initCause(ex);
throw iae;
throw new IllegalArgumentException(
"Error loading class [" + className + "]: problem with class file or dependent class.", ex);
}
}
@@ -258,7 +253,7 @@ public abstract class ClassUtils {
// SHOULD sit in a package, so a length check is worthwhile.
if (name != null && name.length() <= 8) {
// Could be a primitive - likely.
result = (Class) primitiveTypeNameMap.get(name);
result = primitiveTypeNameMap.get(name);
}
return result;
}
@@ -315,7 +310,7 @@ public abstract class ClassUtils {
* @return the user-defined class
*/
public static Class getUserClass(Class clazz) {
return (clazz != null && clazz.getName().indexOf(CGLIB_CLASS_SEPARATOR) != -1 ?
return (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR) ?
clazz.getSuperclass() : clazz);
}
@@ -436,13 +431,13 @@ public abstract class ClassUtils {
* @return a qualified name for the array class
*/
private static String getQualifiedNameForArray(Class clazz) {
StringBuffer buffer = new StringBuffer();
StringBuilder result = new StringBuilder();
while (clazz.isArray()) {
clazz = clazz.getComponentType();
buffer.append(ClassUtils.ARRAY_SUFFIX);
result.append(ClassUtils.ARRAY_SUFFIX);
}
buffer.insert(0, clazz.getName());
return buffer.toString();
result.insert(0, clazz.getName());
return result.toString();
}
/**
@@ -469,16 +464,16 @@ public abstract class ClassUtils {
}
Class clazz = value.getClass();
if (Proxy.isProxyClass(clazz)) {
StringBuffer buf = new StringBuffer(clazz.getName());
buf.append(" implementing ");
StringBuilder result = new StringBuilder(clazz.getName());
result.append(" implementing ");
Class[] ifcs = clazz.getInterfaces();
for (int i = 0; i < ifcs.length; i++) {
buf.append(ifcs[i].getName());
result.append(ifcs[i].getName());
if (i < ifcs.length - 1) {
buf.append(',');
result.append(',');
}
}
return buf.toString();
return result.toString();
}
else if (clazz.isArray()) {
return getQualifiedNameForArray(clazz);
@@ -566,15 +561,14 @@ public abstract class ClassUtils {
Assert.notNull(methodName, "Method name must not be null");
int count = 0;
Method[] declaredMethods = clazz.getDeclaredMethods();
for (int i = 0; i < declaredMethods.length; i++) {
Method method = declaredMethods[i];
for (Method method : declaredMethods) {
if (methodName.equals(method.getName())) {
count++;
}
}
Class[] ifcs = clazz.getInterfaces();
for (int i = 0; i < ifcs.length; i++) {
count += getMethodCountForName(ifcs[i], methodName);
for (Class ifc : ifcs) {
count += getMethodCountForName(ifc, methodName);
}
if (clazz.getSuperclass() != null) {
count += getMethodCountForName(clazz.getSuperclass(), methodName);
@@ -593,15 +587,14 @@ public abstract class ClassUtils {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(methodName, "Method name must not be null");
Method[] declaredMethods = clazz.getDeclaredMethods();
for (int i = 0; i < declaredMethods.length; i++) {
Method method = declaredMethods[i];
for (Method method : declaredMethods) {
if (method.getName().equals(methodName)) {
return true;
}
}
Class[] ifcs = clazz.getInterfaces();
for (int i = 0; i < ifcs.length; i++) {
if (hasAtLeastOneMethodWithName(ifcs[i], methodName)) {
for (Class ifc : ifcs) {
if (hasAtLeastOneMethodWithName(ifc, methodName)) {
return true;
}
}
@@ -657,6 +650,7 @@ public abstract class ClassUtils {
}
}
catch (NoSuchMethodException ex) {
return null;
}
return null;
}
@@ -832,7 +826,7 @@ public abstract class ClassUtils {
if (CollectionUtils.isEmpty(classes)) {
return "[]";
}
StringBuffer sb = new StringBuffer("[");
StringBuilder sb = new StringBuilder("[");
for (Iterator it = classes.iterator(); it.hasNext(); ) {
Class clazz = (Class) it.next();
sb.append(clazz.getName());
@@ -881,18 +875,17 @@ public abstract class ClassUtils {
if (clazz.isInterface()) {
return new Class[] {clazz};
}
List interfaces = new ArrayList();
List<Class> interfaces = new ArrayList<Class>();
while (clazz != null) {
for (int i = 0; i < clazz.getInterfaces().length; i++) {
Class ifc = clazz.getInterfaces()[i];
if (!interfaces.contains(ifc) &&
(classLoader == null || isVisible(ifc, classLoader))) {
Class[] ifcs = clazz.getInterfaces();
for (Class ifc : ifcs) {
if (!interfaces.contains(ifc) && (classLoader == null || isVisible(ifc, classLoader))) {
interfaces.add(ifc);
}
}
clazz = clazz.getSuperclass();
}
return (Class[]) interfaces.toArray(new Class[interfaces.size()]);
return interfaces.toArray(new Class[interfaces.size()]);
}
/**
@@ -913,7 +906,7 @@ public abstract class ClassUtils {
* @param clazz the class to analyse for interfaces
* @return all interfaces that the given object implements as Set
*/
public static Set getAllInterfacesForClassAsSet(Class clazz) {
public static Set<Class> getAllInterfacesForClassAsSet(Class clazz) {
return getAllInterfacesForClassAsSet(clazz, null);
}
@@ -926,12 +919,12 @@ public abstract class ClassUtils {
* (may be <code>null</code> when accepting all declared interfaces)
* @return all interfaces that the given object implements as Set
*/
public static Set getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) {
public static Set<Class> getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) {
Assert.notNull(clazz, "Class must not be null");
if (clazz.isInterface()) {
return Collections.singleton(clazz);
}
Set interfaces = new LinkedHashSet();
Set<Class> interfaces = new LinkedHashSet<Class>();
while (clazz != null) {
for (int i = 0; i < clazz.getInterfaces().length; i++) {
Class ifc = clazz.getInterfaces()[i];

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.
@@ -30,7 +30,7 @@ public class CommonsLogWriter extends Writer {
private final Log logger;
private final StringBuffer buffer = new StringBuffer();
private final StringBuilder buffer = new StringBuilder();
/**
@@ -49,7 +49,7 @@ public class CommonsLogWriter extends Writer {
this.buffer.setLength(0);
}
else {
this.buffer.append((char) ch);
this.buffer.append(ch);
}
}
@@ -62,7 +62,7 @@ public class CommonsLogWriter extends Writer {
this.buffer.setLength(0);
}
else {
this.buffer.append((char) ch);
this.buffer.append(ch);
}
}
}

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.
@@ -133,7 +133,7 @@ public class DefaultPropertiesPersister implements PropertiesPersister {
}
protected String unescape(String str) {
StringBuffer outBuffer = new StringBuffer(str.length());
StringBuilder result = new StringBuilder(str.length());
for (int index = 0; index < str.length();) {
char c = str.charAt(index++);
if (c == '\\') {
@@ -151,9 +151,9 @@ public class DefaultPropertiesPersister implements PropertiesPersister {
c = '\f';
}
}
outBuffer.append(c);
result.append(c);
}
return outBuffer.toString();
return result.toString();
}
@@ -191,39 +191,39 @@ public class DefaultPropertiesPersister implements PropertiesPersister {
protected String escape(String str, boolean isKey) {
int len = str.length();
StringBuffer outBuffer = new StringBuffer(len * 2);
StringBuilder result = new StringBuilder(len * 2);
for (int index = 0; index < len; index++) {
char c = str.charAt(index);
switch (c) {
case ' ':
if (index == 0 || isKey) {
outBuffer.append('\\');
result.append('\\');
}
outBuffer.append(' ');
result.append(' ');
break;
case '\\':
outBuffer.append("\\\\");
result.append("\\\\");
break;
case '\t':
outBuffer.append("\\t");
result.append("\\t");
break;
case '\n':
outBuffer.append("\\n");
result.append("\\n");
break;
case '\r':
outBuffer.append("\\r");
result.append("\\r");
break;
case '\f':
outBuffer.append("\\f");
result.append("\\f");
break;
default:
if ("=: \t\r\n\f#!".indexOf(c) != -1) {
outBuffer.append('\\');
result.append('\\');
}
outBuffer.append(c);
result.append(c);
}
}
return outBuffer.toString();
return result.toString();
}

View File

@@ -33,10 +33,6 @@ import java.text.ParseException;
*/
public abstract class NumberUtils {
private static final boolean decimalFormatSupportsBigDecimal =
ClassUtils.hasMethod(DecimalFormat.class, "setParseBigDecimal", new Class[] {boolean.class});
/**
* Convert the given number into an instance of the given target class.
* @param number the number to convert
@@ -200,8 +196,7 @@ public abstract class NumberUtils {
boolean resetBigDecimal = false;
if (numberFormat instanceof DecimalFormat) {
decimalFormat = (DecimalFormat) numberFormat;
if (BigDecimal.class.equals(targetClass) && decimalFormatSupportsBigDecimal &&
!decimalFormat.isParseBigDecimal()) {
if (BigDecimal.class.equals(targetClass) && !decimalFormat.isParseBigDecimal()) {
decimalFormat.setParseBigDecimal(true);
resetBigDecimal = true;
}
@@ -211,10 +206,7 @@ public abstract class NumberUtils {
return convertNumberToTargetClass(number, targetClass);
}
catch (ParseException ex) {
IllegalArgumentException iae =
new IllegalArgumentException("Could not parse number: " + ex.getMessage());
iae.initCause(ex);
throw iae;
throw new IllegalArgumentException("Could not parse number: " + ex.getMessage());
}
finally {
if (resetBigDecimal) {

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.
@@ -70,10 +70,12 @@ public abstract class ObjectUtils {
return true;
}
if (declaredExceptions != null) {
for (int i = 0; i < declaredExceptions.length; i++) {
int i = 0;
while (i < declaredExceptions.length) {
if (declaredExceptions[i].isAssignableFrom(ex.getClass())) {
return true;
}
i++;
}
}
return false;
@@ -100,8 +102,8 @@ public abstract class ObjectUtils {
if (array == null) {
return false;
}
for (int i = 0; i < array.length; i++) {
if (nullSafeEquals(array[i], element)) {
for (Object arrayEle : array) {
if (nullSafeEquals(arrayEle, element)) {
return true;
}
}
@@ -565,18 +567,18 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(String.valueOf(array[i]));
sb.append(String.valueOf(array[i]));
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -596,19 +598,19 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -628,18 +630,18 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -659,18 +661,18 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append("'").append(array[i]).append("'");
sb.append("'").append(array[i]).append("'");
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -690,19 +692,19 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -722,19 +724,19 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -754,18 +756,18 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -785,18 +787,18 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
/**
@@ -816,18 +818,18 @@ public abstract class ObjectUtils {
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
sb.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
sb.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
sb.append(ARRAY_END);
return sb.toString();
}
}

View File

@@ -319,10 +319,7 @@ public abstract class ReflectionUtils {
* @param ex the unexpected exception
*/
private static void handleUnexpectedException(Throwable ex) {
// Needs to avoid the chained constructor for JDK 1.4 compatibility.
IllegalStateException isex = new IllegalStateException("Unexpected exception thrown");
isex.initCause(ex);
throw isex;
throw new IllegalStateException("Unexpected exception thrown", ex);
}
/**
@@ -337,8 +334,7 @@ public abstract class ReflectionUtils {
public static boolean declaresException(Method method, Class exceptionType) {
Assert.notNull(method, "Method must not be null");
Class[] declaredExceptions = method.getExceptionTypes();
for (int i = 0; i < declaredExceptions.length; i++) {
Class declaredException = declaredExceptions[i];
for (Class declaredException : declaredExceptions) {
if (declaredException.isAssignableFrom(exceptionType)) {
return true;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-20078the 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.
@@ -203,7 +203,7 @@ public class StopWatch {
* For custom reporting, call getTaskInfo() and use the task info directly.
*/
public String prettyPrint() {
StringBuffer sb = new StringBuffer(shortSummary());
StringBuilder sb = new StringBuilder(shortSummary());
sb.append('\n');
if (!this.keepTaskList) {
sb.append("No task info kept");
@@ -234,7 +234,7 @@ public class StopWatch {
*/
@Override
public String toString() {
StringBuffer sb = new StringBuffer(shortSummary());
StringBuilder sb = new StringBuilder(shortSummary());
if (this.keepTaskList) {
TaskInfo[] tasks = getTaskInfo();
for (int i = 0; i < tasks.length; i++) {

View File

@@ -38,7 +38,7 @@ import java.util.TreeSet;
* for a more comprehensive suite of String utilities.
*
* <p>This class delivers some simple functionality that should really
* be provided by the core Java <code>String</code> and {@link StringBuffer}
* be provided by the core Java <code>String</code> and {@link StringBuilder}
* classes, such as the ability to {@link #replace} all occurrences of a given
* substring in a target string. It also provides easy-to-use methods to convert
* between delimited strings, such as CSV strings, and collections and arrays.
@@ -180,14 +180,14 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuffer buf = new StringBuffer(str);
while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
buf.deleteCharAt(0);
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
sb.deleteCharAt(0);
}
while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) {
buf.deleteCharAt(buf.length() - 1);
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
sb.deleteCharAt(sb.length() - 1);
}
return buf.toString();
return sb.toString();
}
/**
@@ -201,17 +201,17 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuffer buf = new StringBuffer(str);
StringBuilder sb = new StringBuilder(str);
int index = 0;
while (buf.length() > index) {
if (Character.isWhitespace(buf.charAt(index))) {
buf.deleteCharAt(index);
while (sb.length() > index) {
if (Character.isWhitespace(sb.charAt(index))) {
sb.deleteCharAt(index);
}
else {
index++;
}
}
return buf.toString();
return sb.toString();
}
/**
@@ -224,11 +224,11 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuffer buf = new StringBuffer(str);
while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
buf.deleteCharAt(0);
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
sb.deleteCharAt(0);
}
return buf.toString();
return sb.toString();
}
/**
@@ -241,11 +241,11 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuffer buf = new StringBuffer(str);
while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) {
buf.deleteCharAt(buf.length() - 1);
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
sb.deleteCharAt(sb.length() - 1);
}
return buf.toString();
return sb.toString();
}
/**
@@ -258,11 +258,11 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuffer buf = new StringBuffer(str);
while (buf.length() > 0 && buf.charAt(0) == leadingCharacter) {
buf.deleteCharAt(0);
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && sb.charAt(0) == leadingCharacter) {
sb.deleteCharAt(0);
}
return buf.toString();
return sb.toString();
}
/**
@@ -275,11 +275,11 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuffer buf = new StringBuffer(str);
while (buf.length() > 0 && buf.charAt(buf.length() - 1) == trailingCharacter) {
buf.deleteCharAt(buf.length() - 1);
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) {
sb.deleteCharAt(sb.length() - 1);
}
return buf.toString();
return sb.toString();
}
@@ -331,7 +331,7 @@ public abstract class StringUtils {
/**
* Test whether the given string matches the given substring
* at the given index.
* @param str the original string (or StringBuffer)
* @param str the original string (or StringBuilder)
* @param index the index in the original string to start matching against
* @param substring the substring to match at the given index
*/
@@ -374,21 +374,20 @@ public abstract class StringUtils {
if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
return inString;
}
StringBuffer sbuf = new StringBuffer();
// output StringBuffer we'll build up
StringBuilder sb = new StringBuilder();
int pos = 0; // our position in the old string
int index = inString.indexOf(oldPattern);
// the index of an occurrence we've found, or -1
int patLen = oldPattern.length();
while (index >= 0) {
sbuf.append(inString.substring(pos, index));
sbuf.append(newPattern);
sb.append(inString.substring(pos, index));
sb.append(newPattern);
pos = index + patLen;
index = inString.indexOf(oldPattern, pos);
}
sbuf.append(inString.substring(pos));
sb.append(inString.substring(pos));
// remember to append any characters to the right of a match
return sbuf.toString();
return sb.toString();
}
/**
@@ -412,14 +411,14 @@ public abstract class StringUtils {
if (!hasLength(inString) || !hasLength(charsToDelete)) {
return inString;
}
StringBuffer out = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < inString.length(); i++) {
char c = inString.charAt(i);
if (charsToDelete.indexOf(c) == -1) {
out.append(c);
sb.append(c);
}
}
return out.toString();
return sb.toString();
}
@@ -493,15 +492,15 @@ public abstract class StringUtils {
if (str == null || str.length() == 0) {
return str;
}
StringBuffer buf = new StringBuffer(str.length());
StringBuilder sb = new StringBuilder(str.length());
if (capitalize) {
buf.append(Character.toUpperCase(str.charAt(0)));
sb.append(Character.toUpperCase(str.charAt(0)));
}
else {
buf.append(Character.toLowerCase(str.charAt(0)));
sb.append(Character.toLowerCase(str.charAt(0)));
}
buf.append(str.substring(1));
return buf.toString();
sb.append(str.substring(1));
return sb.toString();
}
/**

View File

@@ -46,13 +46,13 @@ public abstract class SystemPropertyUtils {
* @see #PLACEHOLDER_SUFFIX
*/
public static String resolvePlaceholders(String text) {
StringBuffer buf = new StringBuffer(text);
StringBuilder result = new StringBuilder(text);
int startIndex = buf.indexOf(PLACEHOLDER_PREFIX);
int startIndex = result.indexOf(PLACEHOLDER_PREFIX);
while (startIndex != -1) {
int endIndex = buf.indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length());
int endIndex = result.indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length());
if (endIndex != -1) {
String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
String placeholder = result.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
int nextIndex = endIndex + PLACEHOLDER_SUFFIX.length();
try {
String propVal = System.getProperty(placeholder);
@@ -61,7 +61,7 @@ public abstract class SystemPropertyUtils {
propVal = System.getenv(placeholder);
}
if (propVal != null) {
buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal);
result.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal);
nextIndex = startIndex + propVal.length();
}
else {
@@ -73,14 +73,14 @@ public abstract class SystemPropertyUtils {
System.err.println("Could not resolve placeholder '" + placeholder + "' in [" + text +
"] as system property: " + ex);
}
startIndex = buf.indexOf(PLACEHOLDER_PREFIX, nextIndex);
startIndex = result.indexOf(PLACEHOLDER_PREFIX, nextIndex);
}
else {
startIndex = -1;
}
}
return buf.toString();
return result.toString();
}
}

View File

@@ -128,15 +128,15 @@ public abstract class DomUtils {
*/
public static String getTextValue(Element valueEle) {
Assert.notNull(valueEle, "Element must not be null");
StringBuffer value = new StringBuffer();
StringBuilder sb = new StringBuilder();
NodeList nl = valueEle.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
value.append(item.getNodeValue());
sb.append(item.getNodeValue());
}
}
return value.toString();
return sb.toString();
}
/**