summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-23 14:10:32 +0800
committerkeuin <[email protected]>2021-01-23 14:10:32 +0800
commit4a1d885afa7217b47d6183488c3dc6537cef05b6 (patch)
tree1b499db6b834cb0709029e30c0d52c0ddf200ffa /src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java
parent4ac575330130ac4e1b4b35386ffc0aacd431a5a4 (diff)
Version 1.4.6 (preview): added metadata for incremental backup (need integrated test and display implementation)
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.java30
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);
+ }
+}