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
ConstructorsConstructorDescriptionDefault constructor.ExecutionContext(Map<String, Object> map) Initializes a new execution context with the contents of another map.ExecutionContext(ExecutionContext executionContext) Initializes a newExecutionContextwith the contents of anotherExecutionContext. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the dirty flag.booleancontainsKey(String key) Indicates whether or not a key is represented in this context.booleancontainsValue(Object value) Indicates whether or not a value is represented in this context.entrySet()Returns the entry set containing the contents of this context.booleanGetter for the value represented by the provided key.doubleTypesafe Getter for the Double represented by the provided key.doubleTypesafe Getter for the Double represented by the provided key with default value to return if key is not represented.intTypesafe Getter for the Integer represented by the provided key.intTypesafe Getter for the Integer represented by the provided key with default value to return if key is not represented.longTypesafe Getter for the Long represented by the provided key.longTypesafe 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.inthashCode()booleanisDirty()Indicates if context has been changed with a "put" operation since the dirty flag was last cleared.booleanisEmpty()Indicates whether or not the context is empty.voidAdd an Object value to the context.voidAdd a Double value to the context.voidAdds an Integer value to the context.voidAdds a Long value to the context.voidAdds a String value to the context.Removes the mapping for a key from this context if it is present.intsize()Returns number of entries in the contexttoString()
-
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 newExecutionContextwith 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. Puttingnullvalue 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. Puttingnullvalue 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
Stringvalue
-
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
Stringvalue 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
Longvalue
-
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
longvalue 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
Integervalue
-
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
intvalue 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
Doublevalue
-
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
doublevalue 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
nullif the key is not present
-
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:
- A set representing the contents of the context
- 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-Stringthat 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:
-