diff options
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java new file mode 100644 index 0000000..4e8a379 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java @@ -0,0 +1,30 @@ +package com.keuin.kbackupfabric.backup.incremental; + +import com.keuin.kbackupfabric.util.backup.incremental.ObjectCollection; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Convert legacy `ObjectCollection` (keep for backward-compatibility after refactoring the code) + * to new `ObjectCollection2`. + */ +public class ObjectCollectionConverter { + /** + * Convert legacy `ObjectCollection` (keep for backward-compatibility after refactoring the code) + * to new `ObjectCollection2`. + * + * @param objectCollection old instance. + * @return new instance. + */ + public static ObjectCollection2 convert(ObjectCollection objectCollection) { + Map<String, ObjectCollection> oldSubCollectionMap = objectCollection.getSubCollectionMap(); + Map<String, ObjectCollection2> convertedSubCollectionMap = new HashMap<>(oldSubCollectionMap.size()); + oldSubCollectionMap.forEach((s, c) -> convertedSubCollectionMap.put(s, convert(c))); + Set<ObjectElement> convertedElementSet = new HashSet<>(); + objectCollection.getElementSet().forEach(oldElement -> convertedElementSet.add(ObjectElementConverter.convert(oldElement))); + return new ObjectCollection2(objectCollection.getName(), convertedElementSet, convertedSubCollectionMap); + } +} |