Explain what 'deepCopy' means

This commit is contained in:
Marcus Holl
2019-05-15 14:21:19 +02:00
parent 7a7fd3ebab
commit a0649aa63f
+10 -3
View File
@@ -63,6 +63,13 @@ class MapUtils implements Serializable {
m.putAll(updates) m.putAll(updates)
} }
/*
* Provides a new map with the same content like the original map.
* Nested Collections and Maps are copied. Values with are not
* Collections/Maps are not copied/cloned.
* <paranoia>&/ltThe keys are also not copied/cloned, even if they are
* Maps or Collections;paranoia>
*/
static deepCopy(Map original) { static deepCopy(Map original) {
Map copy = [:] Map copy = [:]
for (def e : original.entrySet()) { for (def e : original.entrySet()) {
@@ -75,14 +82,14 @@ class MapUtils implements Serializable {
copy copy
} }
static deepCopy(Set original) { /* private */ static deepCopy(Set original) {
Set copy = [] Set copy = []
for(def e : original) for(def e : original)
copy << deepCopy(e) copy << deepCopy(e)
copy copy
} }
static deepCopy(List original) { /* private */ static deepCopy(List original) {
List copy = [] List copy = []
for(def e : original) for(def e : original)
copy << deepCopy(e) copy << deepCopy(e)
@@ -93,7 +100,7 @@ class MapUtils implements Serializable {
* In fact not a copy, but a catch all for everything not matching * In fact not a copy, but a catch all for everything not matching
* with the other signatures * with the other signatures
*/ */
static deepCopy(def original) { /* private */ static deepCopy(def original) {
original original
} }
} }