From 4a52f5e6ce06cb6717510c6a975d5490be627c98 Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 12 Jan 2021 15:03:23 +0800 Subject: Add unit test for Sha256Identifier and ObjectCollection --- .../util/backup/incremental/ObjectCollection.java | 45 +++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollection.java') 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 elements; - private final Set subCollections; + private final Map elements; + private final Map subCollections; - ObjectCollection(String name, Set elements, Set subCollections) { + ObjectCollection(String name, Set elements, Map 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 getElements() { - return elements; + public Set getElementSet() { + return new HashSet<>(elements.values()); + } + + public Map getElementMap() { + return Collections.unmodifiableMap(elements); + } + + public ObjectElement getElement(String name) { + return elements.get(name); + } + + public Set getSubCollectionSet() { + return new HashSet<>(subCollections.values()); + } + + public Map getSubCollectionMap() { + return Collections.unmodifiableMap(subCollections); } - public Set getSubCollections() { - return subCollections; + public ObjectCollection getSubCollection(String name) { + return subCollections.get(name); } @Override -- cgit v1.2.3