diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetterTests.java index 803724752..f0d197e3c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JobParametersPreparedStatementSetterTests.java @@ -30,7 +30,6 @@ import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; -import org.springframework.util.ClassUtils; /** * @author Lucas Ward diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java index e21116278..721dbd958 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java @@ -33,6 +33,7 @@ import org.springframework.util.Assert; * called. * * @author Lucas Ward + * @author Douglas Kaminsky */ public class ExecutionContext { @@ -40,29 +41,63 @@ public class ExecutionContext { private final Map map; + /** + * Default constructor. Initializes a new execution context with an + * empty internal map. + */ public ExecutionContext() { map = new HashMap(); } + /** + * Initializes a new execution context with the contents of another map. + * + * @param map Initial contents of context. + */ public ExecutionContext(Map map) { this.map = map; } + /** + * Adds a String value to the context. + * + * @param key Key to add to context + * @param value Value to associate with key + */ + public void putString(String key, String value) { put(key, value); } + /** + * Adds a Long value to the context. + * + * @param key Key to add to context + * @param value Value to associate with key + */ public void putLong(String key, long value) { put(key, new Long(value)); } - + + /** + * Add a Double value to the context. + * + * @param key Key to add to context + * @param value Value to associate with key + */ public void putDouble(String key, double value) { put(key, new Double(value)); } - + + /** + * Add an Object value to the context (must be Serializable). + * + * @param key Key to add to context + * @param value Value to associate with key + */ public void put(String key, Object value) { if(value != null){ Assert.isInstanceOf(Serializable.class, value, "Value: [ " + value + "must be serializable."); @@ -71,29 +106,68 @@ public class ExecutionContext { map.put(key, value); } + /** + * Indicates if context has been changed with a "put" operation since the + * dirty flag was last cleared. Note that the last time the flag was cleared + * might correspond to creation of the context. + * + * @return True if "put" operation has occurred since flag was last cleared + */ public boolean isDirty() { return dirty; } + /** + * Typesafe Getter for the String represented by the provided key. + * + * @param key The key to get a value for + * @return The String value + */ public String getString(String key) { return (String) readAndValidate(key, String.class); } + /** + * Typesafe Getter for the Long represented by the provided key. + * + * @param key The key to get a value for + * @return The Long value + */ public long getLong(String key) { return ((Long) readAndValidate(key, Long.class)).longValue(); } + /** + * Typesafe Getter for the Double represented by the provided key. + * + * @param key The key to get a value for + * @return The Double value + */ public double getDouble(String key) { return ((Double) readAndValidate(key, Double.class)).doubleValue(); } + /** + * Getter for the value represented by the provided key. + * + * @param key The key to get a value for + * @return The value represented by the given key + */ public Object get(String key) { return map.get(key); } + /** + * Utility method that attempts to take a value represented by a given + * key and validate it as a member of the specified type. + * + * @param key The key to validate a value for + * @param type Class against which value should be validated + * @return Value typed to the specified Class + */ private Object readAndValidate(String key, Class type) { Object value = map.get(key); @@ -106,28 +180,62 @@ public class ExecutionContext { return value; } + /** + * Indicates whether or not the context is empty. + * + * @return True if the context has no entries, false otherwise. + * @see java.util.Map#isEmpty() + */ public boolean isEmpty() { return map.isEmpty(); } + /** + * Clears the dirty flag. + */ public void clearDirtyFlag() { dirty = false; } + /** + * Returns the entry set containing the contents of this context. + * + * @return A set representing the contents of the context + * @see java.util.Map#entrySet() + */ public Set entrySet() { return map.entrySet(); } + /** + * Indicates whether or not a key is represented in this context. + * + * @param key Key to check existence for + * @return True if key is represented in context, false otherwise + * @see java.util.Map#containsKey(Object) + */ public boolean containsKey(String key) { return map.containsKey(key); } + /** + * Indicates whether or not a value is represented in this context. + * + * @param value Value to check existence for + * @return True if value is represented in context, false otherwise + * @see java.util.Map#containsValue(Object) + */ public boolean containsValue(Object value) { return map.containsValue(value); } + /** + * Returns a Properties object containing String + * versions of the contents of the context. + * + * @return Contents of context as a {@link java.util.Properties} + */ public Properties getProperties() { - Properties props = new Properties(); for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Entry entry = (Entry) it.next(); @@ -137,6 +245,10 @@ public class ExecutionContext { return props; } + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ public boolean equals(Object obj) { if (obj instanceof ExecutionContext == false) { return false; @@ -148,14 +260,28 @@ public class ExecutionContext { return this.entrySet().equals(rhs.entrySet()); } + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ public int hashCode() { return map.hashCode(); } + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ public String toString() { return map.toString(); } + /** + * Returns number of entries in the context + * + * @return Number of entries in the context + * @see java.util.Map#size() + */ public int size() { return map.size(); }