Skip to content

Commit

Permalink
add getMapClone helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Apr 14, 2024
1 parent 9c6c301 commit 584acc9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions jpos/src/main/java/org/jpos/transaction/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,17 @@ public synchronized Map<Object,Object> getMap() {
return map;
}

public Map<Object,Object> getMapClone() {
Map<Object,Object> cloned = Collections.synchronizedMap (new LinkedHashMap<>());
synchronized(getMap()) {
cloned.putAll(map);
}
return cloned;
}

protected void dumpMap (PrintStream p, String indent) {
if (map != null) {
Map<Object,Object> cloned;
cloned = Collections.synchronizedMap (new LinkedHashMap<>());
synchronized(map) {
cloned.putAll(map);
}
cloned.entrySet().forEach(e -> dumpEntry(p, indent, e));
getMapClone().entrySet().forEach(e -> dumpEntry(p, indent, e));
}
}

Expand Down

0 comments on commit 584acc9

Please sign in to comment.