IN PROGRESS - BATCH-672: removed redundant casts and boxing/unboxing, converted to for each loops, general cleanup

This commit is contained in:
trisberg
2008-08-01 00:50:13 +00:00
parent f9ca0e17c7
commit ccb2467cce
51 changed files with 53 additions and 135 deletions

View File

@@ -20,11 +20,11 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi
private Map<Object, ExitStatus> mappings;
public ExitStatus getExitStatus(int exitCode) {
ExitStatus exitStatus = (ExitStatus) mappings.get(new Integer(exitCode));
ExitStatus exitStatus = mappings.get(exitCode);
if (exitStatus != null) {
return exitStatus;
} else {
return (ExitStatus) mappings.get(ELSE_KEY);
return mappings.get(ELSE_KEY);
}
}

View File

@@ -41,13 +41,13 @@ public final class FieldSetResultSetExtractor {
* Processes single row in ResultSet and returns its FieldSet representation.
* @param rs ResultSet ResultSet to extract data from.
* @return FieldSet representation of current row in ResultSet
* @throws SQLException
* @throws SQLException thrown during processing
*/
public static FieldSet getFieldSet(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
FieldSet fs = null;
FieldSet fs;
List<String> tokens = new ArrayList<String>();
List<String> names = new ArrayList<String>();
@@ -57,7 +57,7 @@ public final class FieldSetResultSetExtractor {
names.add(metaData.getColumnName(i));
}
fs = new DefaultFieldSet((String[])tokens.toArray(new String[0]), (String[])names.toArray(new String[0]));
fs = new DefaultFieldSet(tokens.toArray(new String[0]), names.toArray(new String[0]));
return fs;
}

View File

@@ -31,22 +31,22 @@ public class LogAdvice {
private static Log log = LogFactory.getLog(LogAdvice.class);
/**
/*
* Wraps original method and adds logging both before and after method
*/
public void doBasicLogging(JoinPoint pjp) throws Throwable {
Object[] args = pjp.getArgs();
StringBuffer output = new StringBuffer();
output.append(pjp.getTarget().getClass().getName()+": ");
output.append(pjp.toShortString()+": ");
for(int i = 0; i < args.length; i++){
output.append(args[i] + " ");
}
log.info("Basic: " + output.toString());
output.append(pjp.getTarget().getClass().getName()).append(": ");
output.append(pjp.toShortString()).append(": ");
for (Object arg : args) {
output.append(arg).append(" ");
}
log.info("Basic: " + output.toString());
}
public void doStronglyTypedLogging(Object item){

View File

@@ -72,7 +72,7 @@ public class StagingItemWriter<T> extends JdbcDaoSupport implements StepExecutio
*/
public void write(T data) {
final long id = incrementer.nextLongValue();
final long jobId = stepExecution.getJobExecution().getJobId().longValue();
final long jobId = stepExecution.getJobExecution().getJobId();
final byte[] blob = SerializationUtils.serialize((Serializable) data);
getJdbcTemplate().update("INSERT into BATCH_STAGING (ID, JOB_ID, VALUE, PROCESSED) values (?,?,?,?)",
new PreparedStatementSetter() {

View File

@@ -64,7 +64,7 @@ public class OrderItemReader extends AbstractItemReader<Order> {
recordFinished = false;
while (!recordFinished) {
process((FieldSet) fieldSetReader.read());
process(fieldSetReader.read());
}
log.info("Mapped: " + order);

View File

@@ -71,7 +71,7 @@ public class OrderTransformer implements ItemTransformer<Order, List<String>> {
}
private LineAggregator getAggregator(String name) {
return (LineAggregator) aggregators.get(name);
return aggregators.get(name);
}
/**

View File

@@ -27,11 +27,7 @@ import org.springmodules.validation.valang.functions.Function;
* @author peter.zozom
*/
public class FutureDateFunction extends AbstractFunction {
/**
* @param arguments
* @param line
* @param column
*/
public FutureDateFunction(Function[] arguments, int line, int column) {
super(arguments, line, column);
definedExactNumberOfArguments(1);
@@ -44,7 +40,7 @@ public class FutureDateFunction extends AbstractFunction {
//get argument
final Object value = getArguments()[0].getResult(target);
Boolean result = Boolean.FALSE;
Boolean result;
if (value instanceof Date) {
final Date now = new Date(System.currentTimeMillis());

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.sample.domain.order.internal.valang;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.order.LineItem;
@@ -41,7 +40,7 @@ public class TotalOrderItemsFunction extends AbstractFunction {
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
//get arguments
int count = ((Integer) getArguments()[0].getResult(target)).intValue();
int count = (Integer) getArguments()[0].getResult(target);
Object value = getArguments()[1].getResult(target);
Boolean result;
@@ -50,11 +49,11 @@ public class TotalOrderItemsFunction extends AbstractFunction {
if (value instanceof List) {
int totalItems = 0;
for (Iterator<LineItem> i = ((List<LineItem>) value).iterator(); i.hasNext();) {
totalItems += i.next().getQuantity();
}
for (LineItem lineItem : ((List<LineItem>) value)) {
totalItems += lineItem.getQuantity();
}
result = (totalItems == count) ? Boolean.TRUE : Boolean.FALSE;
result = (totalItems == count) ? Boolean.TRUE : Boolean.FALSE;
} else {
throw new Exception("No list for validation");
}

View File

@@ -62,7 +62,7 @@ public class PersonService {
return person;
}
/**
/*
* Badly designed method signature which accepts multiple implicitly related
* arguments instead of a single Person argument.
*/

View File

@@ -27,13 +27,9 @@ public class PersonWriter extends AbstractItemWriter<Person> {
private static Log log = LogFactory.getLog(PersonWriter.class);
public void write(Person data) {
if (!(data instanceof Person)) {
log.warn("PersonProcessor can process only Person objects, skipping record");
return;
}
log.debug("Processing: " + data);
}
}

View File

@@ -23,7 +23,7 @@ package org.springframework.batch.sample.domain.trade;
* @author Robert Kasanicky
*/
public interface TradeDao {
/**
/*
* Write a trade object to some kind of output, different implementations
* can write to file, database etc.
*/

View File

@@ -61,7 +61,6 @@ public class JobExecutionNotificationPublisher implements ApplicationListener, N
logger.info(message);
publish(message);
}
return;
}
/**

View File

@@ -10,10 +10,6 @@ public class SimpleMessageApplicationEvent extends ApplicationEvent {
private String message;
/**
* @param source
* @param message
*/
public SimpleMessageApplicationEvent(Object source, String message) {
super(source);
this.message = message;

View File

@@ -55,13 +55,9 @@ public class StepExecutionApplicationEventAdvice implements ApplicationEventPubl
publish(jp.getTarget(), msg);
}
/**
* Publish a {@link RepeatOperationsApplicationEvent} with the given
/*
* Publish a {@link SimpleMessageApplicationEvent} with the given
* parameters.
*
* @param context the current batch context
* @param message the message to publish
* @param type the type of event to publish
*/
private void publish(Object source, String message) {
applicationEventPublisher.publishEvent(new SimpleMessageApplicationEvent(source, message));

View File

@@ -37,7 +37,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
Map<String, String> result = new HashMap<String, String>(configurations);
for (String jobName : registry.getJobNames()) {
try {
Job configuration = (Job) registry.getJob(jobName);
Job configuration = registry.getJob(jobName);
String name = configuration.getName();
if (!configurations.containsKey(name)) {
result.put(name, "<unknown path>: " + configuration);
@@ -54,8 +54,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { path },
applicationContext);
String[] names = context.getBeanNamesForType(Job.class);
for (int i = 0; i < names.length; i++) {
String name = names[i];
for (String name : names) {
configurations.put(name, path);
}
}
@@ -88,8 +87,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
String name = path.substring(0, index);
Object bean = getJobConfiguration(name);
Assert.notNull(bean, "No JobConfiguration exists with name=" + name);
BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
return wrapper;
return new BeanWrapperImpl(bean);
}
}

View File

@@ -76,7 +76,7 @@ public class JobLauncherDetails extends QuartzJobBean {
}
}
/**
/*
* Copy parameters that are of the correct type over to
* {@link JobParameters}, ignoring jobName.
*
@@ -93,10 +93,10 @@ public class JobLauncherDetails extends QuartzJobBean {
builder.addString(key, (String) value);
}
else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, (Double) value);
builder.addDouble(key, ((Number) value).doubleValue());
}
else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, (Long) value);
builder.addLong(key, ((Number)value).longValue());
}
else if (value instanceof Date) {
builder.addDate(key, (Date) value);

View File

@@ -24,10 +24,10 @@ public class FileDeletingTasklet implements Tasklet, InitializingBean {
Assert.state(dir.isDirectory());
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
boolean deleted = files[i].delete();
for (File file : files) {
boolean deleted = file.delete();
if (!deleted) {
throw new UnexpectedJobExecutionException("Could not delete file " + files[i].getPath());
throw new UnexpectedJobExecutionException("Could not delete file " + file.getPath());
}
}
return ExitStatus.FINISHED;