diff options
author | Keuin <[email protected]> | 2021-01-23 14:10:32 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2021-01-23 14:10:32 +0800 |
commit | 4a1d885afa7217b47d6183488c3dc6537cef05b6 (patch) | |
tree | 1b499db6b834cb0709029e30c0d52c0ddf200ffa /src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java | |
parent | 4ac575330130ac4e1b4b35386ffc0aacd431a5a4 (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/util/backup/incremental/ObjectCollection.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java new file mode 100644 index 0000000..d36ff59 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java @@ -0,0 +1,73 @@ +package com.keuin.kbackupfabric.util.backup.incremental; + +import java.io.Serializable; +import java.util.*; + +/** + * This class must be in package `com.keuin.kbackupfabric.util.backup.incremental.ObjectCollection`, + * or it will not be compatible with old backups. + * It remains only to keep a backward compatibility, and should be converted to `ObjectCollection2` as soon as possible. + */ +@Deprecated +public class ObjectCollection implements Serializable { + + private static final long serialVersionUID = -3098905094513096717L; + private final String name; + private final Map<String, ObjectElement> elements; + private final Map<String, ObjectCollection> subCollections; + + ObjectCollection(String name, Set<ObjectElement> elements, Map<String, ObjectCollection> subCollections) { + this.name = Objects.requireNonNull(name); + this.elements = new HashMap<>(); + for (ObjectElement e : elements) { + Objects.requireNonNull(e); + if (this.elements.put(e.getName(), e) != null) { + throw new IllegalStateException("elements conflict with the same name"); + } + } + this.subCollections = new HashMap<>(Objects.requireNonNull(subCollections)); + } + + public String getName() { + return name; + } + + public Set<ObjectElement> getElementSet() { + return new HashSet<>(elements.values()); + } + + public Map<String, ObjectElement> getElementMap() { + return Collections.unmodifiableMap(elements); + } + + public ObjectElement getElement(String name) { + return elements.get(name); + } + + public Set<ObjectCollection> getSubCollectionSet() { + return new HashSet<>(subCollections.values()); + } + + public Map<String, ObjectCollection> getSubCollectionMap() { + return Collections.unmodifiableMap(subCollections); + } + + public ObjectCollection getSubCollection(String name) { + return subCollections.get(name); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ObjectCollection that = (ObjectCollection) o; + return name.equals(that.name) && + elements.equals(that.elements) && + subCollections.equals(that.subCollections); + } + + @Override + public int hashCode() { + return Objects.hash(name, elements, subCollections); + } +} |