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

This commit is contained in:
robokaso
2008-07-16 07:52:43 +00:00
parent 45ec739c3d
commit 36241225ba
4 changed files with 41 additions and 33 deletions

View File

@@ -37,14 +37,14 @@ public class ExecutionContext implements Serializable {
private boolean dirty = false;
private final Map<Object, Object> map;
private final Map<String, Object> map;
/**
* Default constructor. Initializes a new execution context with an empty
* internal map.
*/
public ExecutionContext() {
map = new HashMap<Object, Object>();
map = new HashMap<String, Object>();
}
/**
@@ -52,7 +52,7 @@ public class ExecutionContext implements Serializable {
*
* @param map Initial contents of context.
*/
public ExecutionContext(Map<Object, Object> map) {
public ExecutionContext(Map<String, Object> map) {
this.map = map;
}
@@ -64,7 +64,7 @@ public class ExecutionContext implements Serializable {
if (executionContext == null) {
return;
}
for (Entry<Object, Object> entry : executionContext.entrySet()) {
for (Entry<String, Object> entry : executionContext.entrySet()) {
this.map.put(entry.getKey(), entry.getValue());
}
}
@@ -265,7 +265,7 @@ public class ExecutionContext implements Serializable {
* @return A set representing the contents of the context
* @see java.util.Map#entrySet()
*/
public Set<Entry<Object, Object>> entrySet() {
public Set<Entry<String, Object>> entrySet() {
return map.entrySet();
}
@@ -302,8 +302,8 @@ public class ExecutionContext implements Serializable {
*/
public Properties getProperties() {
Properties props = new Properties();
for (Entry<Object, Object> entry : map.entrySet()) {
props.setProperty(entry.getKey().toString(), entry.getValue().toString());
for (Entry<String, Object> entry : map.entrySet()) {
props.setProperty(entry.getKey(), entry.getValue().toString());
}
return props;

View File

@@ -19,7 +19,6 @@ package org.springframework.batch.item.file.mapping;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -86,7 +85,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
private BeanFactory beanFactory;
private static Map propertiesMatched = new HashMap();
private static Map<Class<?>, Map<String, String>> propertiesMatched = new HashMap<Class<?>, Map<String, String>>();
private static int distanceLimit = 5;
@@ -126,7 +125,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
*
* @param type the type to set
*/
public void setTargetType(Class type) {
public void setTargetType(Class<?> type) {
this.type = type;
}
@@ -227,23 +226,23 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
* @param properties
* @return
*/
@SuppressWarnings("unchecked")
private Properties getBeanProperties(Object bean, Properties properties) {
Class cls = bean.getClass();
Class<?> cls = bean.getClass();
// Map from field names to property names
Map matches = (Map) propertiesMatched.get(cls);
Map<String, String> matches = propertiesMatched.get(cls);
if (matches == null) {
matches = new HashMap();
matches = new HashMap<String, String>();
propertiesMatched.put(cls, matches);
}
Set keys = new HashSet(properties.keySet());
for (Iterator iter = keys.iterator(); iter.hasNext();) {
String key = (String) iter.next();
Set<String> keys = new HashSet(properties.keySet());
for (String key : keys) {
if (matches.containsKey(key)) {
switchPropertyNames(properties, key, (String) matches.get(key));
switchPropertyNames(properties, key, matches.get(key));
continue;
}
@@ -260,7 +259,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
private String findPropertyName(Object bean, String key) {
Class cls = bean.getClass();
Class<?> cls = bean.getClass();
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(key);
String prefix;

View File

@@ -128,7 +128,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
* @throws Exception
*/
public void testRestoreFromEmptyData() throws Exception {
ExecutionContext streamContext = new ExecutionContext(new Properties());
ExecutionContext streamContext = new ExecutionContext(new ExecutionContext());
getAsItemStream(itemReader).open(streamContext);
@@ -201,11 +201,9 @@ public class DrivingQueryItemReaderTests extends TestCase {
static final String RESTART_KEY = "restart.keys";
static {
Properties props = new Properties();
// restart data properties cannot be empty.
props.setProperty("", "");
streamContext = new ExecutionContext(props);
streamContext = new ExecutionContext();
streamContext.put("", "");
}
public MockKeyGenerator() {

View File

@@ -49,7 +49,8 @@ public class StepExecutionMessageHandlerTests {
/**
* Test method for
* {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setStep(org.springframework.batch.core.Step)}.
* {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setStep(org.springframework.batch.core.Step)}
* .
*/
@Test
public void testSetStep() {
@@ -63,7 +64,8 @@ public class StepExecutionMessageHandlerTests {
/**
* Test method for
* {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setJobRepository(org.springframework.batch.core.repository.JobRepository)}.
* {@link org.springframework.batch.integration.job.StepExecutionMessageHandler#setJobRepository(org.springframework.batch.core.repository.JobRepository)}
* .
*/
@Test
public void testSetJobRepository() {
@@ -97,7 +99,7 @@ public class StepExecutionMessageHandlerTests {
JobExecutionRequest message = handler.handle(jobExecutionRequest);
assertEquals(1, message.getJobExecution().getStepExecutions().size());
JobExecution jobExecution = message.getJobExecution();
assertTrue(jobExecution .getExecutionContext().containsKey("foo"));
assertTrue(jobExecution.getExecutionContext().containsKey("foo"));
}
@SuppressWarnings("unchecked")
@@ -117,8 +119,8 @@ public class StepExecutionMessageHandlerTests {
});
JobExecutionRequest message = handler.handle(jobExecutionRequest);
JobExecution jobExecution = message.getJobExecution();
assertTrue(jobExecution .getExecutionContext().containsKey("foo"));
assertTrue(jobExecution .getExecutionContext().containsKey("bar"));
assertTrue(jobExecution.getExecutionContext().containsKey("foo"));
assertTrue(jobExecution.getExecutionContext().containsKey("bar"));
}
@SuppressWarnings("unchecked")
@@ -140,14 +142,20 @@ public class StepExecutionMessageHandlerTests {
public StepExecution getLastStepExecution(JobInstance jobInstance, Step step) {
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
stepExecution.setStatus(BatchStatus.FAILED);
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter
.stringToProperties("foo=bar")));
stepExecution.setExecutionContext(new ExecutionContext() {
{
put("foo", "bar");
}
});
return stepExecution;
}
/*
* (non-Javadoc)
* @see org.springframework.integration.batch.JobRepositorySupport#getStepExecutionCount(org.springframework.batch.core.JobInstance,
*
* @seeorg.springframework.integration.batch.JobRepositorySupport#
* getStepExecutionCount(org.springframework.batch.core.JobInstance,
* org.springframework.batch.core.Step)
*/
@Override
@@ -172,8 +180,11 @@ public class StepExecutionMessageHandlerTests {
public StepExecution getLastStepExecution(JobInstance jobInstance, Step step) {
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
stepExecution.setStatus(BatchStatus.COMPLETED);
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter
.stringToProperties("foo=bar")));
stepExecution.setExecutionContext(new ExecutionContext() {
{
put("foo", "bar");
}
});
return stepExecution;
}
};