From 4a1d885afa7217b47d6183488c3dc6537cef05b6 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 23 Jan 2021 14:10:32 +0800 Subject: Version 1.4.6 (preview): added metadata for incremental backup (need integrated test and display implementation) --- .../incremental/ObjectCollectionConverter.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionConverter.java') 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 oldSubCollectionMap = objectCollection.getSubCollectionMap(); + Map convertedSubCollectionMap = new HashMap<>(oldSubCollectionMap.size()); + oldSubCollectionMap.forEach((s, c) -> convertedSubCollectionMap.put(s, convert(c))); + Set convertedElementSet = new HashSet<>(); + objectCollection.getElementSet().forEach(oldElement -> convertedElementSet.add(ObjectElementConverter.convert(oldElement))); + return new ObjectCollection2(objectCollection.getName(), convertedElementSet, convertedSubCollectionMap); + } +} -- cgit v1.2.3