summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-12 15:03:23 +0800
committerkeuin <[email protected]>2021-01-12 15:03:23 +0800
commit4a52f5e6ce06cb6717510c6a975d5490be627c98 (patch)
tree8fe3602acbaaf74e6946d8a970e84f7a3394c106 /src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java
parentafd26cdd12fef4bd2aafa2ac8d708e18d277a2fe (diff)
Add unit test for Sha256Identifier and ObjectCollection
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.java45
1 files changed, 32 insertions, 13 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
index d5d766a..e0ef4f7 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java
@@ -1,31 +1,50 @@
package com.keuin.kbackupfabric.util.backup.incremental;
-import com.keuin.kbackupfabric.util.backup.incremental.identifier.ObjectIdentifier;
-
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
public class ObjectCollection {
private final String name;
- private final Set<ObjectIdentifier> elements;
- private final Set<ObjectCollection> subCollections;
+ private final Map<String, ObjectElement> elements;
+ private final Map<String, ObjectCollection> subCollections;
- ObjectCollection(String name, Set<ObjectIdentifier> elements, Set<ObjectCollection> subCollections) {
+ ObjectCollection(String name, Set<ObjectElement> elements, Map<String, ObjectCollection> subCollections) {
this.name = Objects.requireNonNull(name);
- this.elements = Objects.requireNonNull(elements);
- this.subCollections = Objects.requireNonNull(subCollections);
+ 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<ObjectIdentifier> getElements() {
- return elements;
+ 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 Set<ObjectCollection> getSubCollections() {
- return subCollections;
+ public ObjectCollection getSubCollection(String name) {
+ return subCollections.get(name);
}
@Override