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/09 19:30:34 UTC

[sling-org-apache-sling-query] branch master updated (4b33e7b -> d54e6f6)

This is an automated email from the ASF dual-hosted git repository.

jeb pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-query.git.


    from 4b33e7b  SLING-7524 release Set after iteration
     new c955cc4  SLING-7540 LastIterator improvements
     new 36c22f3  SLING-7540 SuppIterator improvement
     new d54e6f6  SLING-7540 AlternativeIterator improvement

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../sling/query/iterator/AlternativeIterator.java  |  8 +--
 .../apache/sling/query/iterator/LastIterator.java  | 62 ++++++++--------------
 .../apache/sling/query/iterator/SuppIterator.java  | 51 +++++++++++-------
 3 files changed, 57 insertions(+), 64 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.

[sling-org-apache-sling-query] 02/03: SLING-7540 SuppIterator improvement

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-query.git

commit 36c22f3b11a64a02064bb3f135f6cfbed87c7bcf
Author: JE Bailey <je...@apache.org>
AuthorDate: Fri Mar 9 14:29:01 2018 -0500

    SLING-7540 SuppIterator improvement
    
    Removed recursion on Option determination
---
 .../apache/sling/query/iterator/SuppIterator.java  | 51 ++++++++++++++--------
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/sling/query/iterator/SuppIterator.java b/src/main/java/org/apache/sling/query/iterator/SuppIterator.java
index fafd2a2..8fae602 100644
--- a/src/main/java/org/apache/sling/query/iterator/SuppIterator.java
+++ b/src/main/java/org/apache/sling/query/iterator/SuppIterator.java
@@ -26,9 +26,10 @@ import org.apache.sling.query.api.internal.IteratorToIteratorFunction;
 import org.apache.sling.query.api.internal.Option;
 
 /**
- * This iterator returns all elements of the input list which are mapped to non-empty values by the input
- * function. Name is inspired by the <a href="http://en.wikipedia.org/wiki/Support_(mathematics)">support of
- * the function</a>.
+ * This iterator returns all elements of the input list which are mapped to
+ * non-empty values by the input function. Name is inspired by the
+ * <a href="http://en.wikipedia.org/wiki/Support_(mathematics)">support of the
+ * function</a>.
  */
 public class SuppIterator<T> extends AbstractIterator<Option<T>> {
 
@@ -46,29 +47,43 @@ public class SuppIterator<T> extends AbstractIterator<Option<T>> {
 	}
 
 	/**
-	 * The idea behind this method is that index of each element in the input iterator is passed to the
-	 * function. Elements returned by the output iterator contains the same index, which can be used to assign
-	 * input to output elements. We check which indices are present in the output iterator and return only
-	 * related input elements.
+	 * The idea behind this method is that index of each element in the input
+	 * iterator is passed to the function. One or more Option<T> items for each
+	 * index will be returned. If any Option<T> item in that index set is not
+	 * empty then the corresponding element in the input will be returned.
 	 */
 	@Override
 	protected Option<T> getElement() {
-		if (outputElement != null) {
-			final int outputIndex = outputElement.getArgumentId();
-			if (currentIndex < outputIndex) {
-				return Option.empty(input.get(currentIndex++).getArgumentId());
-			} else if (currentIndex == outputIndex && !outputElement.isEmpty()) {
-				return input.get(currentIndex++);
+		if (outputElement == null) {
+			if (!output.hasNext()) {
+				return null;
 			}
+			outputElement = output.next();
 		}
 
-		while (output.hasNext()) {
+		int outputIndex = outputElement.getArgumentId();
+		boolean emptyResponse = outputElement.isEmpty();
+
+		//loop to next index or end of list
+		while (outputIndex <= currentIndex && output.hasNext()) {
+			if (emptyResponse) {
+				emptyResponse = outputElement.isEmpty();
+			}
 			outputElement = output.next();
-			final int outputIndex = outputElement.getArgumentId();
-			if ((outputIndex == currentIndex && !outputElement.isEmpty()) || outputIndex > currentIndex) {
-				return getElement();
+			outputIndex = outputElement.getArgumentId();
+		}
+
+		if (emptyResponse) {
+			if (outputIndex > currentIndex) {
+				return Option.empty(currentIndex++);
 			}
+			return null;
+		}
+
+		if (outputIndex <= currentIndex) {
+			outputElement = null;
 		}
-		return null;
+		return input.get(currentIndex++);
 	}
+
 }

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.

[sling-org-apache-sling-query] 01/03: SLING-7540 LastIterator improvements

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-query.git

commit c955cc411a67db7ffd83d390051b5104376a5b57
Author: JE Bailey <je...@apache.org>
AuthorDate: Fri Mar 9 14:27:52 2018 -0500

    SLING-7540 LastIterator improvements
    
    Removed pre-determination of the last item to make it more "lazy"
---
 .../apache/sling/query/iterator/LastIterator.java  | 62 ++++++++--------------
 1 file changed, 22 insertions(+), 40 deletions(-)

diff --git a/src/main/java/org/apache/sling/query/iterator/LastIterator.java b/src/main/java/org/apache/sling/query/iterator/LastIterator.java
index b02621f..2316b97 100644
--- a/src/main/java/org/apache/sling/query/iterator/LastIterator.java
+++ b/src/main/java/org/apache/sling/query/iterator/LastIterator.java
@@ -20,60 +20,42 @@
 package org.apache.sling.query.iterator;
 
 import java.util.Iterator;
-import java.util.ListIterator;
 
 import org.apache.sling.query.api.internal.Option;
-import org.apache.sling.query.util.LazyList;
 
+/**
+ * 
+ * 
+ *
+ * @param <T>
+ */
 public class LastIterator<T> extends AbstractIterator<Option<T>> {
 
-	private final LazyList<Option<T>> lazyList;
-
-	private final ListIterator<Option<T>> iterator;
-
-	private boolean finished;
+	private final Iterator<Option<T>> iterator;
 
-	private boolean initialized;
-
-	private int lastIndex = -1;
+	private Option<T> previous;
 
 	public LastIterator(Iterator<Option<T>> iterator) {
-		this.lazyList = new LazyList<Option<T>>(iterator);
-		this.iterator = lazyList.listIterator();
+		this.iterator = iterator;
 	}
 
 	@Override
 	protected Option<T> getElement() {
-		if (finished) {
-			return null;
-		}
-
-		initializeLastIndex();
-
-		Option<T> candidate;
-		if (iterator.hasNext()) {
-			candidate = iterator.next();
-		} else {
-			finished = true;
-			return null;
-		}
-		if (iterator.previousIndex() == lastIndex) {
-			finished = true;
+		Option<T> candidate = previous;
+		
+		if (!iterator.hasNext()) {
+			previous = null;
 			return candidate;
-		} else {
-			return Option.empty(candidate.getArgumentId());
-		}
-	}
-
-	private void initializeLastIndex() {
-		ListIterator<Option<T>> i = lazyList.listIterator();
-		if (!initialized) {
-			while (i.hasNext()) {
-				if (!i.next().isEmpty()) {
-					lastIndex = i.previousIndex();
-				}
+		} 
+		
+		if (candidate == null) {
+			candidate = iterator.next();
+			if (!iterator.hasNext()) {
+				return candidate;
 			}
 		}
-		initialized = true;
+		previous = iterator.next();
+		return Option.empty(candidate.getArgumentId());
 	}
+
 }

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.

[sling-org-apache-sling-query] 03/03: SLING-7540 AlternativeIterator improvement

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-query.git

commit d54e6f67312eb59307b45ed53e06592c2b316b11
Author: JE Bailey <je...@apache.org>
AuthorDate: Fri Mar 9 14:30:01 2018 -0500

    SLING-7540 AlternativeIterator improvement
    
    Returns once item has been identified.
---
 .../java/org/apache/sling/query/iterator/AlternativeIterator.java | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/query/iterator/AlternativeIterator.java b/src/main/java/org/apache/sling/query/iterator/AlternativeIterator.java
index 9b0a5bb..ce78b9a 100644
--- a/src/main/java/org/apache/sling/query/iterator/AlternativeIterator.java
+++ b/src/main/java/org/apache/sling/query/iterator/AlternativeIterator.java
@@ -34,15 +34,11 @@ public class AlternativeIterator<T> extends AbstractIterator<Option<T>> {
 
 	@Override
 	protected Option<T> getElement() {
-		Option<T> element = null;
 		for (Iterator<Option<T>> i : iterators) {
 			if (i.hasNext()) {
-				Option<T> option = i.next();
-				if (element == null || !option.isEmpty()) {
-					element = option;
-				}
+				return i.next();
 			}
 		}
-		return element;
+		return null;
 	}
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.