You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by je...@apache.org on 2018/03/07 13:30:34 UTC
[sling-org-apache-sling-query] branch SLING-7524 updated:
SLING-7524 updated doc and post iteration clean up
This is an automated email from the ASF dual-hosted git repository.
jeb pushed a commit to branch SLING-7524
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-query.git
The following commit(s) were added to refs/heads/SLING-7524 by this push:
new a3e5aa1 SLING-7524 updated doc and post iteration clean up
a3e5aa1 is described below
commit a3e5aa18bcf31afbf1794b7a6cc8541510a07e53
Author: JE Bailey <je...@apache.org>
AuthorDate: Wed Mar 7 08:30:30 2018 -0500
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.
---
src/main/java/org/apache/sling/query/AbstractQuery.java | 3 ++-
.../org/apache/sling/query/iterator/UniqueIterator.java | 14 ++++++++++++--
2 files changed, 14 insertions(+), 3 deletions(-)
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 @@ public abstract class AbstractQuery<T, Q extends AbstractQuery<T, Q>> implements
}
/**
- * 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 @@ public class UniqueIterator<T> extends AbstractIterator<Option<T>> {
@Override
protected Option<T> getElement() {
if (!iterator.hasNext()) {
+ iterator = Collections.emptyIterator();
+ seen = null;
return null;
}
Option<T> candidate = iterator.next();
--
To stop receiving notification emails like this one, please contact
jeb@apache.org.