1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Explain what 'deepCopy' means

This commit is contained in:
Marcus Holl 2019-05-15 14:21:19 +02:00
parent 7a7fd3ebab
commit a0649aa63f

View File

@ -63,6 +63,13 @@ class MapUtils implements Serializable {
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) {
Map copy = [:]
for (def e : original.entrySet()) {
@ -75,14 +82,14 @@ class MapUtils implements Serializable {
copy
}
static deepCopy(Set original) {
/* private */ static deepCopy(Set original) {
Set copy = []
for(def e : original)
copy << deepCopy(e)
copy
}
static deepCopy(List original) {
/* private */ static deepCopy(List original) {
List copy = []
for(def e : original)
copy << deepCopy(e)
@ -93,7 +100,7 @@ class MapUtils implements Serializable {
* In fact not a copy, but a catch all for everything not matching
* with the other signatures
*/
static deepCopy(def original) {
/* private */ static deepCopy(def original) {
original
}
}