File tree Expand file tree Collapse file tree 3 files changed +16
-20
lines changed
spring-batch-core/src/main/java/org/springframework/batch/core/scope/context
spring-batch-infrastructure/src/main/java/org/springframework/batch/item Expand file tree Collapse file tree 3 files changed +16
-20
lines changed Original file line number Diff line number Diff line change @@ -82,11 +82,7 @@ public Properties getSystemProperties() {
82
82
* @return a map containing the items from the job {@link ExecutionContext}
83
83
*/
84
84
public Map <String , Object > getJobExecutionContext () {
85
- Map <String , Object > result = new HashMap <>();
86
- for (Entry <String , Object > entry : jobExecution .getExecutionContext ().entrySet ()) {
87
- result .put (entry .getKey (), entry .getValue ());
88
- }
89
- return Collections .unmodifiableMap (result );
85
+ return jobExecution .getExecutionContext ().toMap ();
90
86
}
91
87
92
88
/**
Original file line number Diff line number Diff line change @@ -111,22 +111,14 @@ public Properties getSystemProperties() {
111
111
* @return a map containing the items from the step {@link ExecutionContext}
112
112
*/
113
113
public Map <String , Object > getStepExecutionContext () {
114
- Map <String , Object > result = new HashMap <>();
115
- for (Entry <String , Object > entry : stepExecution .getExecutionContext ().entrySet ()) {
116
- result .put (entry .getKey (), entry .getValue ());
117
- }
118
- return Collections .unmodifiableMap (result );
114
+ return stepExecution .getExecutionContext ().toMap ();
119
115
}
120
116
121
117
/**
122
118
* @return a map containing the items from the job {@link ExecutionContext}
123
119
*/
124
120
public Map <String , Object > getJobExecutionContext () {
125
- Map <String , Object > result = new HashMap <>();
126
- for (Entry <String , Object > entry : stepExecution .getJobExecution ().getExecutionContext ().entrySet ()) {
127
- result .put (entry .getKey (), entry .getValue ());
128
- }
129
- return Collections .unmodifiableMap (result );
121
+ return stepExecution .getJobExecution ().getExecutionContext ().toMap ();
130
122
}
131
123
132
124
/**
Original file line number Diff line number Diff line change 17
17
package org .springframework .batch .item ;
18
18
19
19
import java .io .Serializable ;
20
+ import java .util .Collections ;
20
21
import java .util .Map ;
21
22
import java .util .Map .Entry ;
22
23
import java .util .Set ;
@@ -69,9 +70,7 @@ public ExecutionContext(ExecutionContext executionContext) {
69
70
if (executionContext == null ) {
70
71
return ;
71
72
}
72
- for (Entry <String , Object > entry : executionContext .entrySet ()) {
73
- this .map .put (entry .getKey (), entry .getValue ());
74
- }
73
+ this .map .putAll (executionContext .toMap ());
75
74
}
76
75
77
76
/**
@@ -293,11 +292,20 @@ public void clearDirtyFlag() {
293
292
294
293
/**
295
294
* Returns the entry set containing the contents of this context.
296
- * @return A set representing the contents of the context
295
+ * @return An unmodifiable set representing the contents of the context
297
296
* @see java.util.Map#entrySet()
298
297
*/
299
298
public Set <Entry <String , Object >> entrySet () {
300
- return this .map .entrySet ();
299
+ return Collections .unmodifiableSet (this .map .entrySet ());
300
+ }
301
+
302
+ /**
303
+ * Returns the internal map as read-only.
304
+ * @return An unmodifiable map containing all contents.
305
+ * @see java.util.Map
306
+ */
307
+ public Map <String , Object > toMap () {
308
+ return Collections .unmodifiableMap (this .map );
301
309
}
302
310
303
311
/**
You can’t perform that action at this time.
0 commit comments