IN PROGRESS - BATCH-709: Change all collections to use generics

This commit is contained in:
robokaso
2008-07-15 12:39:16 +00:00
parent 23f05f59cc
commit c7825d49be
5 changed files with 35 additions and 59 deletions

View File

@@ -17,8 +17,8 @@
package org.springframework.batch.repeat.exception;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -39,12 +39,11 @@ import org.springframework.util.Assert;
*/
public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
protected final Log logger = LogFactory
.getLog(RethrowOnThresholdExceptionHandler.class);
protected final Log logger = LogFactory.getLog(RethrowOnThresholdExceptionHandler.class);
private ExceptionClassifier exceptionClassifier = new ExceptionClassifierSupport();
private Map thresholds = new HashMap();
private Map<Object, Integer> thresholds = new HashMap<Object, Integer>();
private boolean useParent = false;
@@ -52,9 +51,8 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
* Flag to indicate the the exception counters should be shared between
* sibling contexts in a nested batch. Default is false.
*
* @param useParent
* true if the parent context should be used to store the
* counters.
* @param useParent true if the parent context should be used to store the
* counters.
*/
public void setUseParent(boolean useParent) {
this.useParent = useParent;
@@ -75,21 +73,16 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
* are usually String literals, depending on the {@link ExceptionClassifier}
* implementation used.
*
* @param thresholds
* the threshold value map.
* @param thresholds the threshold value map.
*/
public void setThresholds(Map thresholds) {
for (Iterator iter = thresholds.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
public void setThresholds(Map<Object, Integer> thresholds) {
for (Entry<Object, Integer> entry : thresholds.entrySet()) {
if (!(entry.getKey() instanceof String)) {
logger.warn("Key in thresholds map is not of type String: "
+ entry.getKey());
logger.warn("Key in thresholds map is not of type String: " + entry.getKey());
}
Assert
.state(
entry.getValue() instanceof Integer,
"Threshold value must be of type Integer. "
+ "Try using the value-type attribute if you care configuring this map via xml.");
Assert.state(entry.getValue() instanceof Integer, "Threshold value must be of type Integer. "
+ "Try using the value-type attribute if you care configuring this map via xml.");
}
this.thresholds = thresholds;
}
@@ -114,14 +107,13 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
* @throws Throwable
* @see ExceptionHandler#handleException(RepeatContext, Throwable)
*/
public void handleException(RepeatContext context, Throwable throwable)
throws Throwable {
public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
Object key = exceptionClassifier.classify(throwable);
RepeatContextCounter counter = getCounter(context, key);
counter.increment();
int count = counter.getCount();
Integer threshold = (Integer) thresholds.get(key);
Integer threshold = thresholds.get(key);
if (threshold == null || count > threshold.intValue()) {
throw throwable;
}
@@ -129,8 +121,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
}
private RepeatContextCounter getCounter(RepeatContext context, Object key) {
String attribute = RethrowOnThresholdExceptionHandler.class.getName() + "."
+ key.toString();
String attribute = RethrowOnThresholdExceptionHandler.class.getName() + "." + key.toString();
// Creates a new counter and stores it in the correct context:
return new RepeatContextCounter(context, attribute, useParent);
}

View File

@@ -47,9 +47,9 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
private RethrowOnThresholdExceptionHandler delegate = new RethrowOnThresholdExceptionHandler();
private Class[] exceptionClasses = new Class[] { Exception.class };
private Class<?>[] exceptionClasses = new Class[] { Exception.class };
private Class[] fatalExceptionClasses = new Class[] { Error.class };
private Class<?>[] fatalExceptionClasses = new Class[] { Error.class };
/**
* Flag to indicate the the exception counters should be shared between
@@ -116,7 +116,7 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
* @param limit
*/
public void setLimit(final int limit) {
delegate.setThresholds(new HashMap() {
delegate.setThresholds(new HashMap<Object, Integer>() {
{
put(ExceptionClassifierSupport.DEFAULT, new Integer(0));
put(TX_INVALID, new Integer(limit));
@@ -131,7 +131,7 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
* handler uses single counter that is incremented when one of the
* recognized exception exceptionClasses is handled.
*/
public void setExceptionClasses(Class[] classes) {
public void setExceptionClasses(Class<? extends Throwable>[] classes) {
this.exceptionClasses = classes;
}
@@ -142,7 +142,7 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
*
* @param fatalExceptionClasses defaults to {@link Error}
*/
public void setFatalExceptionClasses(Class[] fatalExceptionClasses) {
public void setFatalExceptionClasses(Class<?>[] fatalExceptionClasses) {
this.fatalExceptionClasses = fatalExceptionClasses;
}

View File

@@ -17,7 +17,6 @@ package org.springframework.batch.repeat.listener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.repeat.ExitStatus;
@@ -30,7 +29,7 @@ import org.springframework.batch.repeat.RepeatListener;
*/
public class CompositeRepeatListener implements RepeatListener {
private List listeners = new ArrayList();
private List<RepeatListener> listeners = new ArrayList<RepeatListener>();
/**
* Public setter for the listeners.
@@ -56,8 +55,7 @@ public class CompositeRepeatListener implements RepeatListener {
* @see org.springframework.batch.repeat.RepeatListener#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus)
*/
public void after(RepeatContext context, ExitStatus result) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
RepeatListener listener = (RepeatListener) iterator.next();
for (RepeatListener listener : listeners) {
listener.after(context, result);
}
}
@@ -66,8 +64,7 @@ public class CompositeRepeatListener implements RepeatListener {
* @see org.springframework.batch.repeat.RepeatListener#before(org.springframework.batch.repeat.RepeatContext)
*/
public void before(RepeatContext context) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
RepeatListener listener = (RepeatListener) iterator.next();
for (RepeatListener listener : listeners) {
listener.before(context);
}
}
@@ -76,8 +73,7 @@ public class CompositeRepeatListener implements RepeatListener {
* @see org.springframework.batch.repeat.RepeatListener#close(org.springframework.batch.repeat.RepeatContext)
*/
public void close(RepeatContext context) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
RepeatListener listener = (RepeatListener) iterator.next();
for (RepeatListener listener : listeners) {
listener.close(context);
}
}
@@ -86,8 +82,7 @@ public class CompositeRepeatListener implements RepeatListener {
* @see org.springframework.batch.repeat.RepeatListener#onError(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)
*/
public void onError(RepeatContext context, Throwable e) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
RepeatListener listener = (RepeatListener) iterator.next();
for (RepeatListener listener : listeners) {
listener.onError(context, e);
}
}
@@ -96,8 +91,7 @@ public class CompositeRepeatListener implements RepeatListener {
* @see org.springframework.batch.repeat.RepeatListener#open(org.springframework.batch.repeat.RepeatContext)
*/
public void open(RepeatContext context) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
RepeatListener listener = (RepeatListener) iterator.next();
for (RepeatListener listener : listeners) {
listener.open(context);
}
}

View File

@@ -83,7 +83,7 @@ public class CompositeCompletionPolicy implements CompletionPolicy {
* @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext)
*/
public RepeatContext start(RepeatContext context) {
List list = new ArrayList();
List<RepeatContext> list = new ArrayList<RepeatContext>();
for (int i = 0; i < policies.length; i++) {
list.add(policies[i].start(context));
}
@@ -121,9 +121,9 @@ public class CompositeCompletionPolicy implements CompletionPolicy {
// change).
private CompletionPolicy[] policies;
public CompositeBatchContext(RepeatContext context, List contexts) {
public CompositeBatchContext(RepeatContext context, List<RepeatContext> contexts) {
super(context);
this.contexts = (RepeatContext[]) contexts.toArray(new RepeatContext[contexts.size()]);
this.contexts = contexts.toArray(new RepeatContext[contexts.size()]);
this.policies = CompositeCompletionPolicy.this.policies;
}