Fix some PMD violations where it made sense

This commit is contained in:
dsyer
2010-01-14 12:50:48 +00:00
parent 09d852285f
commit 5c8f527443
26 changed files with 79 additions and 60 deletions

View File

@@ -76,7 +76,7 @@ public class ClassifierAdapter<C, T> implements Classifier<C, T> {
*
* @param delegate an object with an annotated method
*/
public void setDelegate(Object delegate) {
public final void setDelegate(Object delegate) {
classifier = null;
invoker = MethodInvokerUtils.getMethodInvokerByAnnotation(
org.springframework.batch.support.annotation.Classifier.class, delegate);

View File

@@ -63,7 +63,7 @@ public class SubclassClassifier<T, C> implements Classifier<T, C> {
*/
public SubclassClassifier(Map<Class<? extends T>, C> typeMap, C defaultValue) {
super();
setTypeMap(typeMap);
this.classified = new HashMap<Class<? extends T>, C>(typeMap);
this.defaultValue = defaultValue;
}

View File

@@ -207,7 +207,7 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
* is assumed correct values will be supplied at runtime.
*/
public void setArguments(Object[] arguments) {
this.arguments = arguments;
this.arguments = Arrays.asList(arguments).toArray();
}
/**

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.item.adapter;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.item.ItemWriter;
@@ -68,7 +69,8 @@ public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInv
* are supported, e.g. <code>address.city</code>
*/
public void setFieldsUsedAsTargetMethodArguments(String[] fieldsUsedAsMethodArguments) {
this.fieldsUsedAsTargetMethodArguments = fieldsUsedAsMethodArguments;
this.fieldsUsedAsTargetMethodArguments = Arrays.asList(fieldsUsedAsMethodArguments).toArray(
new String[fieldsUsedAsMethodArguments.length]);
}
}

View File

@@ -47,7 +47,7 @@ import org.springframework.util.ClassUtils;
public class MultiResourceItemReader<T> implements ItemReader<T>, ItemStream {
private static final Log logger = LogFactory.getLog(MultiResourceItemReader.class);
private static final String RESOURCE_KEY = "resourceIndex";
private final ExecutionContextUserSupport executionContextUserSupport = new ExecutionContextUserSupport();
@@ -57,7 +57,7 @@ public class MultiResourceItemReader<T> implements ItemReader<T>, ItemStream {
private Resource[] resources;
private boolean saveState = true;
private int currentResource = -1;
// signals there are no resources to read -> just return null on first read
@@ -86,10 +86,10 @@ public class MultiResourceItemReader<T> implements ItemReader<T>, ItemStream {
if (noInput) {
return null;
}
//If there is no resource, then this is the first item, set the current
//resource to 0 and open the first delegate.
if(currentResource == -1){
// If there is no resource, then this is the first item, set the current
// resource to 0 and open the first delegate.
if (currentResource == -1) {
currentResource = 0;
delegate.setResource(resources[currentResource]);
delegate.open(new ExecutionContext());
@@ -159,7 +159,7 @@ public class MultiResourceItemReader<T> implements ItemReader<T>, ItemStream {
delegate.setResource(resources[currentResource]);
delegate.open(executionContext);
}
else{
else {
currentResource = -1;
}
}
@@ -194,7 +194,7 @@ public class MultiResourceItemReader<T> implements ItemReader<T>, ItemStream {
/**
* @param comparator used to order the injected resources, by default
* compares {@link Resource#getFilename()} values.
* compares {@link Resource#getFilename()} values.
*/
public void setComparator(Comparator<Resource> comparator) {
this.comparator = comparator;
@@ -204,7 +204,7 @@ public class MultiResourceItemReader<T> implements ItemReader<T>, ItemStream {
* @param resources input resources
*/
public void setResources(Resource[] resources) {
this.resources = resources;
this.resources = Arrays.asList(resources).toArray(new Resource[resources.length]);
}
public Resource getCurrentResource() {

View File

@@ -1,5 +1,6 @@
package org.springframework.batch.item.file;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.batch.item.ExecutionContext;
@@ -48,7 +49,7 @@ public class ResourcesItemReader extends ExecutionContextUserSupport implements
* @param resources the resources
*/
public void setResources(Resource[] resources) {
this.resources = resources;
this.resources = Arrays.asList(resources).toArray(new Resource[resources.length]);
}
/**

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.item.file.transform;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -78,7 +79,7 @@ public abstract class AbstractLineTokenizer implements LineTokenizer {
* @param names
*/
public void setNames(String[] names) {
this.names = names;
this.names = Arrays.asList(names).toArray(new String[names.length]);
}
/**

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.item.file.transform;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.BeanWrapper;
@@ -40,7 +41,7 @@ public class BeanWrapperFieldExtractor<T> implements FieldExtractor<T>, Initiali
* @param names field names to be extracted by the {@link #extract(Object)} method.
*/
public void setNames(String[] names) {
this.names = names;
this.names = Arrays.asList(names).toArray(new String[names.length]);
}
/**

View File

@@ -64,7 +64,7 @@ public class DefaultFieldSet implements FieldSet {
* US locale will be used ('.' as decimal place).
* @param numberFormat the {@link NumberFormat} to use for number parsing
*/
public void setNumberFormat(NumberFormat numberFormat) {
public final void setNumberFormat(NumberFormat numberFormat) {
this.numberFormat = numberFormat;
if (numberFormat instanceof DecimalFormat) {
grouping = ""+((DecimalFormat)numberFormat).getDecimalFormatSymbols().getGroupingSeparator();

View File

@@ -96,7 +96,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
*
* @see #DEFAULT_QUOTE_CHARACTER
*/
public void setQuoteCharacter(char quoteCharacter) {
public final void setQuoteCharacter(char quoteCharacter) {
this.quoteCharacter = quoteCharacter;
this.quoteString = "" + quoteCharacter;
}
@@ -167,9 +167,9 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
if (endLength == 0) {
endLength = 1;
}
string = value.substring(1, endLength);
value = value.substring(1, endLength);
}
return string;
return value;
}
/**

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.item.file.transform;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -49,7 +50,7 @@ public class FixedLengthTokenizer extends AbstractLineTokenizer {
* @param ranges the column ranges expected in the input
*/
public void setColumns(Range[] ranges) {
this.ranges = ranges;
this.ranges = Arrays.asList(ranges).toArray(new Range[ranges.length]);
calculateMaxRange(ranges);
}

View File

@@ -27,7 +27,7 @@ import org.springframework.util.Assert;
*
* @author Peter Zozom
*/
public class FileUtils {
public final class FileUtils {
// forbids instantiation
private FileUtils() {

View File

@@ -148,7 +148,7 @@ public class SynchronizedAttributeAccessor implements AttributeAccessor {
String[] names = attributeNames();
for (int i = 0; i < names.length; i++) {
String name = names[i];
buffer.append(names[i] + "=" + getAttribute(name));
buffer.append(names[i]).append("=").append(getAttribute(name));
if (i < names.length - 1) {
buffer.append(", ");
}

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.repeat.exception;
import java.util.Arrays;
import org.springframework.batch.repeat.RepeatContext;
@@ -30,7 +31,7 @@ public class CompositeExceptionHandler implements ExceptionHandler {
private ExceptionHandler[] handlers = new ExceptionHandler[0];
public void setHandlers(ExceptionHandler[] handlers) {
this.handlers = handlers;
this.handlers = Arrays.asList(handlers).toArray(new ExceptionHandler[handlers.length]);
}
/**

View File

@@ -17,11 +17,12 @@
package org.springframework.batch.repeat.policy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.context.RepeatContextSupport;
/**
@@ -41,7 +42,7 @@ public class CompositeCompletionPolicy implements CompletionPolicy {
* @param policies
*/
public void setPolicies(CompletionPolicy[] policies) {
this.policies = policies;
this.policies = Arrays.asList(policies).toArray(new CompletionPolicy[policies.length]);
}
/**

View File

@@ -33,7 +33,7 @@ import org.springframework.batch.repeat.RepeatOperations;
* @author Dave Syer
*
*/
public class RepeatSynchronizationManager {
public final class RepeatSynchronizationManager {
private static final ThreadLocal<RepeatContext> contextHolder = new ThreadLocal<RepeatContext>();

View File

@@ -24,12 +24,12 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
import org.springframework.batch.repeat.RepeatListener;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.exception.DefaultExceptionHandler;
import org.springframework.batch.repeat.exception.ExceptionHandler;
import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy;
@@ -79,7 +79,7 @@ public class RepeatTemplate implements RepeatOperations {
* @param listeners
*/
public void setListeners(RepeatListener[] listeners) {
this.listeners = listeners;
this.listeners = Arrays.asList(listeners).toArray(new RepeatListener[listeners.length]);
}
/**

View File

@@ -16,6 +16,8 @@
package org.springframework.batch.retry.interceptor;
import java.util.Arrays;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
@@ -37,8 +39,8 @@ import org.springframework.util.ObjectUtils;
* a method on a service if it fails. The argument to the service method is
* treated as an item to be remembered in case the call fails. So the retry
* operation is stateful, and the item that failed is tracked by its unique key
* (via {@link MethodArgumentsKeyGenerator}) until the retry is exhausted, at which point
* the {@link MethodInvocationRecoverer} is called.<br/>
* (via {@link MethodArgumentsKeyGenerator}) until the retry is exhausted, at
* which point the {@link MethodInvocationRecoverer} is called.<br/>
*
* The main use case for this is where the service is transactional, via a
* transaction interceptor on the interceptor chain. In this case the retry (and
@@ -78,10 +80,10 @@ public class StatefulRetryOperationsInterceptor implements MethodInterceptor {
}
/**
* Public setter for the {@link MethodInvocationRecoverer} to use if the retry is
* exhausted. The recoverer should be able to return an object of the same
* type as the target object because its return value will be used to return
* to the caller in the case of a recovery.<br/>
* Public setter for the {@link MethodInvocationRecoverer} to use if the
* retry is exhausted. The recoverer should be able to return an object of
* the same type as the target object because its return value will be used
* to return to the caller in the case of a recovery.<br/>
*
* If no recoverer is set then an exhausted retry will result in an
* {@link ExhaustedRetryException}.
@@ -97,10 +99,11 @@ public class StatefulRetryOperationsInterceptor implements MethodInterceptor {
}
/**
* Public setter for the {@link NewMethodArgumentsIdentifier}. Only set this if the
* arguments to the intercepted method can be inspected to find out if they
* have never been processed before.
* @param newMethodArgumentsIdentifier the {@link NewMethodArgumentsIdentifier} to set
* Public setter for the {@link NewMethodArgumentsIdentifier}. Only set this
* if the arguments to the intercepted method can be inspected to find out
* if they have never been processed before.
* @param newMethodArgumentsIdentifier the
* {@link NewMethodArgumentsIdentifier} to set
*/
public void setNewItemIdentifier(NewMethodArgumentsIdentifier newMethodArgumentsIdentifier) {
this.newMethodArgumentsIdentifier = newMethodArgumentsIdentifier;
@@ -110,10 +113,11 @@ public class StatefulRetryOperationsInterceptor implements MethodInterceptor {
* Wrap the method invocation in a stateful retry with the policy and other
* helpers provided. If there is a failure the exception will generally be
* re-thrown. The only time it is not re-thrown is when retry is exhausted
* and the recovery path is taken (though the {@link MethodInvocationRecoverer} provided
* if there is one). In that case the value returned from the method
* invocation will be the value returned by the recoverer (so the return
* type for that should be the same as the intercepted method).
* and the recovery path is taken (though the
* {@link MethodInvocationRecoverer} provided if there is one). In that case
* the value returned from the method invocation will be the value returned
* by the recoverer (so the return type for that should be the same as the
* intercepted method).
*
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
* @see MethodInvocationRecoverer#recover(Object[], Throwable)
@@ -135,9 +139,11 @@ public class StatefulRetryOperationsInterceptor implements MethodInterceptor {
}
final Object item = arg;
RetryState retryState = new DefaultRetryState(keyGenerator != null ? keyGenerator.getKey(args) : item, newMethodArgumentsIdentifier != null ? newMethodArgumentsIdentifier.isNew(args) : false );
RetryState retryState = new DefaultRetryState(keyGenerator != null ? keyGenerator.getKey(args) : item,
newMethodArgumentsIdentifier != null ? newMethodArgumentsIdentifier.isNew(args) : false);
Object result = retryOperations.execute(new MethodInvocationRetryCallback(invocation), new ItemRecovererCallback(args, recoverer), retryState);
Object result = retryOperations.execute(new MethodInvocationRetryCallback(invocation),
new ItemRecovererCallback(args, recoverer), retryState);
logger.debug("Exiting proxied method in stateful retry with result: (" + result + ")");
@@ -192,7 +198,7 @@ public class StatefulRetryOperationsInterceptor implements MethodInterceptor {
* @param args the item that failed.
*/
private ItemRecovererCallback(Object[] args, MethodInvocationRecoverer<? extends Object> recoverer) {
this.args = args;
this.args = Arrays.asList(args).toArray();
this.recoverer = recoverer;
}

View File

@@ -17,6 +17,7 @@
package org.springframework.batch.retry.policy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.retry.RetryContext;
@@ -40,7 +41,7 @@ public class CompositeRetryPolicy implements RetryPolicy {
* @param policies
*/
public void setPolicies(RetryPolicy[] policies) {
this.policies = policies;
this.policies = Arrays.asList(policies).toArray(new RetryPolicy[policies.length]);
}
/**
@@ -77,12 +78,12 @@ public class CompositeRetryPolicy implements RetryPolicy {
policies[i].close(contexts[i]);
}
catch (RuntimeException e) {
if (exception==null) {
if (exception == null) {
exception = e;
}
}
}
if (exception!=null) {
if (exception != null) {
throw exception;
}
}

View File

@@ -34,7 +34,7 @@ import org.springframework.batch.retry.RetryOperations;
* @author Dave Syer
*
*/
public class RetrySynchronizationManager {
public final class RetrySynchronizationManager {
private RetrySynchronizationManager() {}

View File

@@ -100,7 +100,7 @@ public class RetryTemplate implements RetryOperations {
* @see RetryListener
*/
public void setListeners(RetryListener[] listeners) {
this.listeners = listeners;
this.listeners = Arrays.asList(listeners).toArray(new RetryListener[listeners.length]);
}
/**