Package org.springframework.batch.item
Class ExecutionContext
java.lang.Object
org.springframework.batch.item.ExecutionContext
- All Implemented Interfaces:
Serializable
Object representing a context for an
ItemStream
. It is a thin wrapper for a map
that allows optionally for type safety on reads. It also allows for dirty checking by
setting a 'dirty' flag whenever any put is called.
Non-transient entries should be serializable, otherwise a custom serializer should be
used. Note that putting null
value is equivalent to removing the entry for
the given key.
- Author:
- Lucas Ward, Douglas Kaminsky, Mahmoud Ben Hassine
- See Also:
-
Constructor Summary
ConstructorDescriptionDefault constructor.ExecutionContext
(Map<String, Object> map) Initializes a new execution context with the contents of another map.ExecutionContext
(ExecutionContext executionContext) Initializes a newExecutionContext
with the contents of anotherExecutionContext
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the dirty flag.boolean
containsKey
(String key) Indicates whether or not a key is represented in this context.boolean
containsValue
(Object value) Indicates whether or not a value is represented in this context.entrySet()
Returns the entry set containing the contents of this context.boolean
Getter for the value represented by the provided key.<V> V
Typesafe getter for the value represented by the provided key, with cast to given class.<V> V
Typesafe getter for the value represented by the provided key, with cast to given class.double
Typesafe Getter for the Double represented by the provided key.double
Typesafe Getter for the Double represented by the provided key with default value to return if key is not represented.int
Typesafe Getter for the Integer represented by the provided key.int
Typesafe Getter for the Integer represented by the provided key with default value to return if key is not represented.long
Typesafe Getter for the Long represented by the provided key.long
Typesafe Getter for the Long represented by the provided key with default value to return if key is not represented.Typesafe Getter for the String represented by the provided key.Typesafe Getter for the String represented by the provided key with default value to return if key is not represented.int
hashCode()
boolean
isDirty()
Indicates if context has been changed with a "put" operation since the dirty flag was last cleared.boolean
isEmpty()
Indicates whether or not the context is empty.void
Add an Object value to the context.void
Add a Double value to the context.void
Adds an Integer value to the context.void
Adds a Long value to the context.void
Adds a String value to the context.Removes the mapping for a key from this context if it is present.int
size()
Returns number of entries in the contexttoMap()
Returns the internal map as read-only.toString()
-
Constructor Details
-
ExecutionContext
public ExecutionContext()Default constructor. Initializes a new execution context with an empty internal map. -
ExecutionContext
Initializes a new execution context with the contents of another map.- Parameters:
map
- Initial contents of context.
-
ExecutionContext
Initializes a newExecutionContext
with the contents of anotherExecutionContext
.- Parameters:
executionContext
- containing the entries to be copied to this current context.
-
-
Method Details
-
putString
Adds a String value to the context. Puttingnull
value for a given key removes the key.- Parameters:
key
- Key to add to contextvalue
- Value to associate with key
-
putLong
Adds a Long value to the context.- Parameters:
key
- Key to add to contextvalue
- Value to associate with key
-
putInt
Adds an Integer value to the context.- Parameters:
key
- Key to add to contextvalue
- Value to associate with key
-
putDouble
Add a Double value to the context.- Parameters:
key
- Key to add to contextvalue
- Value to associate with key
-
put
Add an Object value to the context. Puttingnull
value for a given key removes the key.- Parameters:
key
- Key to add to contextvalue
- Value to associate with key
-
isDirty
public boolean isDirty()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.- Returns:
- True if "put" operation has occurred since flag was last cleared
-
getString
Typesafe Getter for the String represented by the provided key.- Parameters:
key
- The key to get a value for- Returns:
- The
String
value
-
getString
Typesafe Getter for the String represented by the provided key with default value to return if key is not represented.- Parameters:
key
- The key to get a value fordefaultString
- Default to return if key is not represented- Returns:
- The
String
value if key is represented, specified default otherwise
-
getLong
Typesafe Getter for the Long represented by the provided key.- Parameters:
key
- The key to get a value for- Returns:
- The
Long
value
-
getLong
Typesafe Getter for the Long represented by the provided key with default value to return if key is not represented.- Parameters:
key
- The key to get a value fordefaultLong
- Default to return if key is not represented- Returns:
- The
long
value if key is represented, specified default otherwise
-
getInt
Typesafe Getter for the Integer represented by the provided key.- Parameters:
key
- The key to get a value for- Returns:
- The
Integer
value
-
getInt
Typesafe Getter for the Integer represented by the provided key with default value to return if key is not represented.- Parameters:
key
- The key to get a value fordefaultInt
- Default to return if key is not represented- Returns:
- The
int
value if key is represented, specified default otherwise
-
getDouble
Typesafe Getter for the Double represented by the provided key.- Parameters:
key
- The key to get a value for- Returns:
- The
Double
value
-
getDouble
Typesafe Getter for the Double represented by the provided key with default value to return if key is not represented.- Parameters:
key
- The key to get a value fordefaultDouble
- Default to return if key is not represented- Returns:
- The
double
value if key is represented, specified default otherwise
-
get
Getter for the value represented by the provided key.- Parameters:
key
- The key to get a value for- Returns:
- The value represented by the given key or
null
if the key is not present
-
get
Typesafe getter for the value represented by the provided key, with cast to given class.- Type Parameters:
V
- Type of returned value- Parameters:
key
- The key to get a value fortype
- The class of return type- Returns:
- The value of given type represented by the given key or
null
if the key is not present - Since:
- 5.1
-
get
Typesafe getter for the value represented by the provided key, with cast to given class.- Type Parameters:
V
- Type of returned value- Parameters:
key
- The key to get a value fortype
- The class of return typedefaultValue
- Default value in case element is not present- Returns:
- The value of given type represented by the given key or the default value if the key is not present
- Since:
- 5.1
-
isEmpty
public boolean isEmpty()Indicates whether or not the context is empty.- Returns:
- True if the context has no entries, false otherwise.
- See Also:
-
clearDirtyFlag
public void clearDirtyFlag()Clears the dirty flag. -
entrySet
Returns the entry set containing the contents of this context.- Returns:
- An unmodifiable set representing the contents of the context
- See Also:
-
toMap
Returns the internal map as read-only.- Returns:
- An unmodifiable map containing all contents.
- Since:
- 5.1
- See Also:
-
containsKey
Indicates whether or not a key is represented in this context.- Parameters:
key
- Key to check existence for- Returns:
- True if key is represented in context, false otherwise
- See Also:
-
remove
Removes the mapping for a key from this context if it is present.- Parameters:
key
-String
that identifies the entry to be removed from the context.- Returns:
- the value that was removed from the context.
- See Also:
-
containsValue
Indicates whether or not a value is represented in this context.- Parameters:
value
- Value to check existence for- Returns:
- True if value is represented in context, false otherwise
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
size
public int size()Returns number of entries in the context- Returns:
- Number of entries in the context
- See Also:
-