SLING-7524 updated doc and post iteration clean up
based on feedback, updated the javadoc as well as removed the reference
for the set of seen objects when the iteration is done.
diff --git a/src/main/java/org/apache/sling/query/AbstractQuery.java b/src/main/java/org/apache/sling/query/AbstractQuery.java
index ea37084..dfbcd51 100644
--- a/src/main/java/org/apache/sling/query/AbstractQuery.java
+++ b/src/main/java/org/apache/sling/query/AbstractQuery.java
@@ -752,7 +752,8 @@
}
/**
- * Filter out repeated adjacent resources.
+ * Filter out duplicated resources in a stream, this iterator is stateful during
+ * the iteration process.
*
* @return new SlingQuery object transformed by this operation
*/
diff --git a/src/main/java/org/apache/sling/query/iterator/UniqueIterator.java b/src/main/java/org/apache/sling/query/iterator/UniqueIterator.java
index e5ad63f..17b1caf 100644
--- a/src/main/java/org/apache/sling/query/iterator/UniqueIterator.java
+++ b/src/main/java/org/apache/sling/query/iterator/UniqueIterator.java
@@ -19,16 +19,24 @@
package org.apache.sling.query.iterator;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.sling.query.api.internal.Option;
+/**
+ * Provides an iteration of unique objects. During the iteration process this
+ * iterator maintains a set of previously seen items that will be used as filter
+ * to prevent duplicates from being iterated through
+ *
+ * @param <T>
+ */
public class UniqueIterator<T> extends AbstractIterator<Option<T>> {
- private final Iterator<Option<T>> iterator;
-
+ private Iterator<Option<T>> iterator;
+
private Set<T> seen;
public UniqueIterator(Iterator<Option<T>> input) {
@@ -39,6 +47,8 @@
@Override
protected Option<T> getElement() {
if (!iterator.hasNext()) {
+ iterator = Collections.emptyIterator();
+ seen = null;
return null;
}
Option<T> candidate = iterator.next();