This is an automated email from the ASF dual-hosted git repository. bertty pushed a commit to branch WAYANG-28-update in repository https://gitbox.apache.org/repos/asf/incubator-wayang.git
commit 301c9abdcf907618f60ce4b36e4b22523dce2e20 Author: Bertty Contreras-Rojas <ber...@scalytics.io> AuthorDate: Thu Apr 29 23:10:20 2021 -0400 [WAYANG-28] Add javadoc to iterator package --- .../hackit/core/iterator/ElementPlusIterator.java | 25 +++++++++++++ .../hackit/core/iterator/FunctionIterator.java | 23 ++++++++++++ .../hackit/core/iterator/HackitIterator.java | 13 ++++++- .../hackit/core/iterator/OneElementIterator.java | 41 ++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/ElementPlusIterator.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/ElementPlusIterator.java index 32e52c90..e3857187 100644 --- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/ElementPlusIterator.java +++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/ElementPlusIterator.java @@ -19,13 +19,38 @@ package org.apache.wayang.plugin.hackit.core.iterator; import java.util.Iterator; +/** + * ElementPlusIterator extends from {@link Iterator}. + * + * ElementPlusIterator add one unique element to a know {@link Iterator}, this unique element + * it will be consumed first. + * + * @param <T> type of the element of the iterator + */ public class ElementPlusIterator<T> implements Iterator<T> { + /** + * Indicate if the first element it was consumed or not yet + */ private boolean element_consumed = false; + + /** + * The element that was included to the iterator + */ private T element; + + /** + * The iterator where the element was added + */ private Iterator<T> iterator; + /** + * Construct of ElementPlusIterator + * + * @param element is the object that will be consumed first + * @param iterator iterator that will be consumed after the original element + */ public ElementPlusIterator(T element, Iterator<T> iterator) { if(element == null){ throw new RuntimeException("the element can't be null"); diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/FunctionIterator.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/FunctionIterator.java index 286566fc..5cb22d85 100644 --- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/FunctionIterator.java +++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/FunctionIterator.java @@ -21,11 +21,34 @@ import java.io.Serializable; import java.util.Iterator; import java.util.function.Function; +/** + * FunctionIterator implements {@link Iterator} and {@link Serializable}, because the function could be + * serializad to be sent to several places at runtime + * + * FunctionIterator provide the option of convert the data in the iterator using an {@link Function}, + * this will transform the element to the new kind + * + * @param <I> Type before of the transformation in the iterator + * @param <O> Type after the transformation, this could be the same to <I> + */ public class FunctionIterator<I, O> implements Iterator<O>, Serializable { + /** + * base is an {@link Iterator} that will be transformed during runtime + */ private Iterator<I> base; + + /** + * function is an {@link Function} that will convert the element inside of <code>base</code> + */ private Function<I, O> function; + /** + * Construct of FunctionIterator + * + * @param base {@link Iterator} that will be transformed at the consumed time + * @param function {@link Function} that will convert the data inside of <code>base</code> + */ public FunctionIterator(Iterator<I> base, Function<I, O> function) { this.base = base; this.function = function; diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/HackitIterator.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/HackitIterator.java index 3ce2f84b..42166d2d 100644 --- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/HackitIterator.java +++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/HackitIterator.java @@ -22,9 +22,20 @@ import org.apache.wayang.plugin.hackit.core.tuple.HackitTuple; import java.util.Iterator; import java.util.function.Function; - +/** + * HackitIterator extends {@link FunctionIterator} and provides an signature for the conversion of + * the tuples into a {@link HackitTuple} during they process. + * + * @param <K> type of the key on the {@link HackitTuple} + * @param <T> type of the element that it contains the {@link HackitTuple} + */ public class HackitIterator<K, T> extends FunctionIterator<T, HackitTuple<K, T>>{ + /** + * default construct + * @param base {@link Iterator} that element will be wrapper inside of a {@link HackitTuple} + * @param function it a {@link Function} that convert the the {@link HackitTuple} + */ public HackitIterator(Iterator<T> base, Function<T, HackitTuple<K, T>> function) { super(base, function); } diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/OneElementIterator.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/OneElementIterator.java index 1ebf412e..811413e1 100644 --- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/OneElementIterator.java +++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/iterator/OneElementIterator.java @@ -20,17 +20,51 @@ package org.apache.wayang.plugin.hackit.core.iterator; import java.util.Iterator; import java.util.NoSuchElementException; +/** + * OneElementIterator implements {@link Iterator} and {@link Iterable} + * + * OneElementIterator will contains just one element, but that element need to be treated as + * Iterator, this class allow handler all the functionality that are related to that. + * + * @param <T> type of the element + */ public class OneElementIterator<T> implements Iterator<T>, Iterable<T>{ + /** + * indicate if the element could be removed + */ private final boolean removeAllowed; + + /** + * Indicate if the process is started or not + */ private boolean beforeFirst; + + /** + * allows to follow the process as the object didn't exist + */ private boolean removed; + + /** + * is the element that it will "process" at the iteration time + */ private T object; + /** + * Default Construct + * + * @param object element that will be process + */ public OneElementIterator(T object) { this(object, true); } + /** + * Construct that allows indicate the option of remove the object + * + * @param object element that will be process + * @param removeAllowed indicate if the element could be removed + */ public OneElementIterator(T object, boolean removeAllowed) { this.beforeFirst = true; this.removed = false; @@ -38,10 +72,12 @@ public class OneElementIterator<T> implements Iterator<T>, Iterable<T>{ this.removeAllowed = removeAllowed; } + @Override public boolean hasNext() { return this.beforeFirst && !this.removed; } + @Override public T next() { if (this.beforeFirst && !this.removed) { this.beforeFirst = false; @@ -51,6 +87,7 @@ public class OneElementIterator<T> implements Iterator<T>, Iterable<T>{ } } + @Override public void remove() { if (this.removeAllowed) { if (!this.removed && !this.beforeFirst) { @@ -64,6 +101,10 @@ public class OneElementIterator<T> implements Iterator<T>, Iterable<T>{ } } + /** + * reset the Iterator if is needed, because the iterator it just one element, then is possible to do several + * full iteration on top of the element. + */ public void reset() { this.beforeFirst = true; }