summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-24 21:15:24 +0800
committerkeuin <[email protected]>2021-01-25 02:12:49 +0800
commit1df50093bd76315905a9aae880470e81b5e1d8f0 (patch)
treef94b4d2847c2da2c820e708b6664c3246992e581 /src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java
parent3648d0ca94c9954fa7c4797ce64a0f42a4f837b5 (diff)
If incremental backup failed, unfinished copy will be fully reverted.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java
new file mode 100644
index 0000000..248d36d
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionIterator.java
@@ -0,0 +1,50 @@
+package com.keuin.kbackupfabric.backup.incremental;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+public class ObjectCollectionIterator implements Iterator<ObjectElement> {
+
+ // TODO: test this
+
+ private Iterator<ObjectElement> currentIterator;
+ private final List<ObjectCollection2> cols = new LinkedList<>();
+
+ public ObjectCollectionIterator(ObjectCollection2 collection) {
+ cols.addAll(collection.getSubCollectionSet());
+ currentIterator = collection.getElementSet().iterator();
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (currentIterator != null) {
+ if (currentIterator.hasNext())
+ return true;
+ else {
+ currentIterator = null;
+ return hasNext();
+ }
+ } else {
+ if (cols.isEmpty())
+ return false;
+ else {
+ ObjectCollection2 consumedCollection = cols.remove(0);
+ cols.addAll(consumedCollection.getSubCollectionSet());
+ currentIterator = consumedCollection.getElementSet().iterator();
+ return hasNext();
+ }
+ }
+ }
+
+ @Override
+ public ObjectElement next() {
+ if (hasNext()) {
+ return currentIterator.next();
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+
+}