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

This commit is contained in:
robokaso
2008-07-17 07:54:04 +00:00
parent c5545a93b7
commit 7e412c75ff
26 changed files with 106 additions and 108 deletions

View File

@@ -49,8 +49,8 @@ public final class FieldSetResultSetExtractor {
FieldSet fs = null;
List tokens = new ArrayList();
List names = new ArrayList();
List<String> tokens = new ArrayList<String>();
List<String> names = new ArrayList<String>();
for (int i = 1; i <= columnCount; i++) {
tokens.add(rs.getString(i));

View File

@@ -33,14 +33,14 @@ public class HibernateCreditDao extends HibernateDaoSupport implements
CustomerCreditDao, RepeatListener {
private int failOnFlush = -1;
private List errors = new ArrayList();
private List<Throwable> errors = new ArrayList<Throwable>();
/**
* Public accessor for the errors property.
*
* @return the errors - a list of Throwable instances
*/
public List getErrors() {
public List<Throwable> getErrors() {
return errors;
}

View File

@@ -40,7 +40,7 @@ public class OrderTransformer implements ItemTransformer {
/**
* Aggregators for all types of lines in the output file
*/
private Map aggregators;
private Map<String, LineAggregator> aggregators;
/**
* Converts information from an Order object to a collection of Strings for
@@ -49,19 +49,17 @@ public class OrderTransformer implements ItemTransformer {
public Object transform(Object data) {
Order order = (Order) data;
List result = new ArrayList();
List<String> result = new ArrayList<String>();
result.add(getAggregator("header").aggregate(OrderFormatterUtils.headerArgs(order)));
result.add(getAggregator("customer").aggregate(OrderFormatterUtils.customerArgs(order)));
result.add(getAggregator("address").aggregate(OrderFormatterUtils.billingAddressArgs(order)));
result.add(getAggregator("billing").aggregate(OrderFormatterUtils.billingInfoArgs(order)));
List items = order.getLineItems();
LineItem item;
List<LineItem> items = order.getLineItems();
for (int i = 0; i < items.size(); i++) {
item = (LineItem) items.get(i);
result.add(getAggregator("item").aggregate(OrderFormatterUtils.lineItemArgs(item)));
for (LineItem lineItem : items) {
result.add(getAggregator("item").aggregate(OrderFormatterUtils.lineItemArgs(lineItem)));
}
result.add(getAggregator("footer").aggregate(OrderFormatterUtils.footerArgs(order)));
@@ -69,7 +67,7 @@ public class OrderTransformer implements ItemTransformer {
return result;
}
public void setAggregators(Map aggregators) {
public void setAggregators(Map<String, LineAggregator> aggregators) {
this.aggregators = aggregators;
}

View File

@@ -44,7 +44,7 @@ public class Order {
private ShippingInfo shipping;
//order items
private List lineItems;
private List<LineItem> lineItems;
public BillingInfo getBilling() {
return billing;
@@ -70,11 +70,11 @@ public class Order {
this.customer = customer;
}
public List getLineItems() {
public List<LineItem> getLineItems() {
return lineItems;
}
public void setLineItems(List lineItems) {
public void setLineItems(List<LineItem> lineItems) {
this.lineItems = lineItems;
}

View File

@@ -30,7 +30,7 @@ public class Person {
private String last_name = "";
private int age = 0;
private Address address = new Address();
private List children = new ArrayList();
private List<Child> children = new ArrayList<Child>();
public Person(){
children.add(new Child());
@@ -76,13 +76,13 @@ public class Person {
/**
* @return the children
*/
public List getChildren() {
public List<Child> getChildren() {
return children;
}
/**
* @param children the children to set
*/
public void setChildren(List children) {
public void setChildren(List<Child> children) {
this.children = children;
}
/**

View File

@@ -44,7 +44,7 @@ public class PersonService {
Person person = new Person();
Address address = new Address();
Child child = new Child();
List children = new ArrayList(1);
List<Child> children = new ArrayList<Child>(1);
children.add(child);

View File

@@ -30,7 +30,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
public class Order {
private Customer customer;
private Date date;
private List lineItems;
private List<LineItem> lineItems;
private Shipper shipper;
public Customer getCustomer() {
@@ -49,11 +49,11 @@ public class Order {
this.date = date;
}
public List getLineItems() {
public List<LineItem> getLineItems() {
return lineItems;
}
public void setLineItems(List lineItems) {
public void setLineItems(List<LineItem> lineItems) {
this.lineItems = lineItems;
}

View File

@@ -162,10 +162,10 @@ public class OrderItemReader extends DelegatingItemReader {
log.debug("MAPPING LINE ITEM");
if (order.getLineItems() == null) {
order.setLineItems(new ArrayList());
order.setLineItems(new ArrayList<LineItem>());
}
order.getLineItems().add(itemMapper.mapLine(fieldSet));
order.getLineItems().add((LineItem) itemMapper.mapLine(fieldSet));
return;
}

View File

@@ -44,7 +44,7 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
private volatile boolean initialized = false;
private volatile Iterator keys;
private volatile Iterator<Long> keys;
/**
* Public setter for the {@link LobHandler}.
@@ -83,7 +83,8 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
}
}
private List retrieveKeys() {
@SuppressWarnings("unchecked")
private List<Long> retrieveKeys() {
synchronized (lock) {
@@ -166,9 +167,9 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
private static class StagingBuffer {
private List list = new ArrayList();
private List<Long> list = new ArrayList<Long>();
private Iterator iter = new ArrayList().iterator();
private Iterator<Long> iter = new ArrayList<Long>().iterator();
public Long next() {
if (iter.hasNext()) {
@@ -183,13 +184,13 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
public void rollback() {
logger.debug("Resetting buffer on rollback: " + list);
iter = new ArrayList(list).iterator();
iter = new ArrayList<Long>(list).iterator();
}
public void commit() {
logger.debug("Clearing buffer on commit: " + list);
list.clear();
iter = new ArrayList().iterator();
iter = new ArrayList<Long>().iterator();
}
public String toString() {

View File

@@ -11,7 +11,7 @@ import org.springframework.batch.item.validator.ValidationException;
*/
public class ItemTrackingItemWriter extends AbstractItemWriter {
private List items = new ArrayList();
private List<Object> items = new ArrayList<Object>();
private int failure = -1;
@@ -25,7 +25,7 @@ public class ItemTrackingItemWriter extends AbstractItemWriter {
}
}
public List getItems() {
public List<Object> getItems() {
return items;
}

View File

@@ -4,7 +4,6 @@
package org.springframework.batch.sample.launch;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.springframework.batch.core.Job;
@@ -18,15 +17,15 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.Assert;
public class DefaultJobLoader implements JobLoader,
ApplicationContextAware {
public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
private ListableJobRegistry registry;
private ApplicationContext applicationContext;
private Map configurations = new HashMap();
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
private ApplicationContext applicationContext;
private Map<String, String> configurations = new HashMap<String, String>();
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@@ -34,12 +33,11 @@ public class DefaultJobLoader implements JobLoader,
this.registry = registry;
}
public Map getConfigurations() {
Map result = new HashMap(configurations);
for (Iterator iterator = registry.getJobNames().iterator(); iterator
.hasNext();) {
public Map<String, String> getConfigurations() {
Map<String, String> result = new HashMap<String, String>(configurations);
for (String jobName : registry.getJobNames()) {
try {
Job configuration = (Job) registry.getJob((String) iterator.next());
Job configuration = (Job) registry.getJob(jobName);
String name = configuration.getName();
if (!configurations.containsKey(name)) {
result.put(name, "<unknown path>: " + configuration);
@@ -53,19 +51,20 @@ public class DefaultJobLoader implements JobLoader,
}
public void loadResource(String path) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { path }, applicationContext);
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];
configurations.put(name, path);
}
}
public Object getJobConfiguration(String name) {
try {
return registry.getJob(name);
} catch (NoSuchJobException e) {
}
catch (NoSuchJobException e) {
return null;
}
}
@@ -73,22 +72,22 @@ public class DefaultJobLoader implements JobLoader,
public Object getProperty(String path) {
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
String key = path.substring(index+1);
String key = path.substring(index + 1);
return wrapper.getPropertyValue(key);
}
public void setProperty(String path, String value) {
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
String key = path.substring(index+1);
String key = path.substring(index + 1);
wrapper.setPropertyValue(key, value);
}
private BeanWrapperImpl createBeanWrapper(String path, int index) {
Assert.state(index>0, "Path must be nested, e.g. bean.value");
String name = path.substring(0,index);
Assert.state(index > 0, "Path must be nested, e.g. bean.value");
String name = path.substring(0, index);
Object bean = getJobConfiguration(name);
Assert.notNull(bean, "No JobConfiguration exists with name="+name);
Assert.notNull(bean, "No JobConfiguration exists with name=" + name);
BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
return wrapper;
}

View File

@@ -26,7 +26,7 @@ public interface ExportedJobLoader {
void loadResource(String path);
Map getConfigurations();
Map<String, String> getConfigurations();
String getJob(String path);

View File

@@ -26,7 +26,7 @@ public interface JobLoader {
void loadResource(String path);
Map getConfigurations();
Map<String, String> getConfigurations();
Object getJobConfiguration(String path);

View File

@@ -42,7 +42,7 @@ public class TaskExecutorLauncher implements ResourceLoaderAware {
private ApplicationContext parentContext = null;
private static List errors = new ArrayList();
private static List<RuntimeException> errors = new ArrayList<RuntimeException>();
/**
* Public setter for the {@link JobRegistry}.
@@ -64,7 +64,7 @@ public class TaskExecutorLauncher implements ResourceLoaderAware {
* Public getter for the errors.
* @return the errors
*/
public static List getErrors() {
public static List<RuntimeException> getErrors() {
return errors;
}

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.sample.quartz;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -63,8 +62,9 @@ public class JobLauncherDetails extends QuartzJobBean {
this.jobLauncher = jobLauncher;
}
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context) {
Map jobDataMap = context.getMergedJobDataMap();
Map<String, Object> jobDataMap = context.getMergedJobDataMap();
String jobName = (String) jobDataMap.get(JOB_NAME);
log.info("Quartz trigger firing with Spring Batch jobName="+jobName);
JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap);
@@ -82,13 +82,12 @@ public class JobLauncherDetails extends QuartzJobBean {
*
* @return a {@link JobParameters} instance
*/
private JobParameters getJobParametersFromJobMap(Map jobDataMap) {
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap) {
JobParametersBuilder builder = new JobParametersBuilder();
for (Iterator iterator = jobDataMap.entrySet().iterator(); iterator.hasNext();) {
Entry entry = (Entry) iterator.next();
String key = (String) entry.getKey();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(JOB_NAME)) {
builder.addString(key, (String) value);

View File

@@ -17,7 +17,7 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi
public static final String ELSE_KEY = "else";
private Map mappings;
private Map<Integer, ExitStatus> mappings;
public ExitStatus getExitStatus(int exitCode) {
ExitStatus exitStatus = (ExitStatus) mappings.get(new Integer(exitCode));
@@ -32,7 +32,7 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi
* @param mappings <code>Integer</code> exit code keys to
* {@link org.springframework.batch.repeat.ExitStatus} values.
*/
public void setMappings(Map mappings) {
public void setMappings(Map<Integer, ExitStatus> mappings) {
Assert.notNull(mappings.get(ELSE_KEY));
this.mappings = mappings;
}

View File

@@ -38,7 +38,8 @@ public class TotalOrderItemsFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
//get arguments
int count = ((Integer) getArguments()[0].getResult(target)).intValue();
Object value = getArguments()[1].getResult(target);
@@ -49,9 +50,8 @@ public class TotalOrderItemsFunction extends AbstractFunction {
if (value instanceof List) {
int totalItems = 0;
for (Iterator i = ((List) value).iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
totalItems += item.getQuantity();
for (Iterator<LineItem> i = ((List<LineItem>) value).iterator(); i.hasNext();) {
totalItems += i.next().getQuantity();
}
result = (totalItems == count) ? Boolean.TRUE : Boolean.FALSE;

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -41,11 +40,11 @@ public class ValidateDiscountsFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if (BD_0.compareTo(item.getDiscountPerc()) != 0) {
//DiscountPerc must be between 0.0 and 100.0

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -41,11 +40,11 @@ public class ValidateHandlingPricesFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if ((BD_MIN.compareTo(item.getHandlingPrice()) > 0)
|| (BD_MAX.compareTo(item.getHandlingPrice()) < 0)) {

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -39,11 +38,11 @@ public class ValidateIdsFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if ((item.getItemId() <= 0) || (item.getItemId() > MAX_ID)) {
return Boolean.FALSE;

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -41,11 +40,11 @@ public class ValidatePricesFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if ((BD_MIN.compareTo(item.getPrice()) > 0) || (BD_MAX.compareTo(item.getPrice()) < 0)) {
return Boolean.FALSE;

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -39,11 +38,11 @@ public class ValidateQuantitiesFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if ((item.getQuantity() <= 0) || (item.getQuantity() > MAX_QUANTITY)) {
return Boolean.FALSE;

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -41,11 +40,11 @@ public class ValidateShippingPricesFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if ((BD_MIN.compareTo(item.getShippingPrice()) > 0)
|| (BD_MAX.compareTo(item.getShippingPrice()) < 0)) {

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.sample.validation.valang.custom;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
@@ -42,11 +41,11 @@ public class ValidateTotalPricesFunction extends AbstractFunction {
/**
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
*/
protected Object doGetResult(Object target) throws Exception {
List lineItems = (List) getArguments()[0].getResult(target);
@SuppressWarnings("unchecked")
protected Object doGetResult(Object target) throws Exception {
List<LineItem> lineItems = (List<LineItem>) getArguments()[0].getResult(target);
for (Iterator i = lineItems.iterator(); i.hasNext();) {
LineItem item = (LineItem) i.next();
for (LineItem item : lineItems) {
if ((BD_MIN.compareTo(item.getTotalPrice()) > 0)
|| (BD_MAX.compareTo(item.getTotalPrice()) < 0)) {