[GitHub] [commons-collections] garydgregory commented on a change in pull request #238: [COLLECTIONS-795] Add a new Iterator to allowing zipping over two iterators of different types

2021-06-04 Thread GitBox


garydgregory commented on a change in pull request #238:
URL: 
https://github.com/apache/commons-collections/pull/238#discussion_r645116336



##
File path: src/main/java/org/apache/commons/collections4/IterableUtils.java
##
@@ -554,6 +555,34 @@
 };
 }
 
+/**
+ * Provides iteration over the elements contained in a pair of Iterables 
in-tandem.
+ * 
+ * The returned iterable has an iterator that traverses the elements in 
{@code a}
+ * and {@code b} together until one of the iterables is traversed 
completely.
+ * 

Review comment:
   Close HTML tags.

##
File path: src/main/java/org/apache/commons/collections4/IteratorUtils.java
##
@@ -127,7 +87,7 @@ private IteratorUtils() {}
  * @return an iterator over nothing
  */
 public static  ResettableIterator emptyIterator() {
-return EmptyIterator.resettableEmptyIterator();
+return EmptyIterator.resettableEmptyIterator();

Review comment:
   These changes are unrelated, small PRs are better for reviewers ;-)

##
File path: src/main/java/org/apache/commons/collections4/IterableUtils.java
##
@@ -554,6 +555,34 @@
 };
 }
 
+/**
+ * Provides iteration over the elements contained in a pair of Iterables 
in-tandem.
+ * 
+ * The returned iterable has an iterator that traverses the elements in 
{@code a}
+ * and {@code b} together until one of the iterables is traversed 
completely.
+ * 
+ * The returned iterable's iterator does NOT support {@code remove()}.
+ *
+ * @param  the left elements' type
+ * @param  the right elements' type
+ * @param left the iterable for the left side elements
+ * @param right the iterable for the right side elements
+ * @return an iterable, over the decorated iterables to traverse them 
together until one is
+ * exhausted
+ * @throws NullPointerException if any iterator is null
+ */

Review comment:
   New public and protected method should have `@since 4.5` Javadoc tags.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-collections] garydgregory commented on a change in pull request #238: [COLLECTIONS-795] Add a new Iterator to allowing zipping over two iterators of different types

2021-06-03 Thread GitBox


garydgregory commented on a change in pull request #238:
URL: 
https://github.com/apache/commons-collections/pull/238#discussion_r645116336



##
File path: src/main/java/org/apache/commons/collections4/IterableUtils.java
##
@@ -554,6 +555,34 @@
 };
 }
 
+/**
+ * Provides iteration over the elements contained in a pair of Iterables 
in-tandem.
+ * 
+ * The returned iterable has an iterator that traverses the elements in 
{@code a}
+ * and {@code b} together until one of the iterables is traversed 
completely.
+ * 

Review comment:
   Close HTML tags.

##
File path: src/main/java/org/apache/commons/collections4/IteratorUtils.java
##
@@ -127,7 +87,7 @@ private IteratorUtils() {}
  * @return an iterator over nothing
  */
 public static  ResettableIterator emptyIterator() {
-return EmptyIterator.resettableEmptyIterator();
+return EmptyIterator.resettableEmptyIterator();

Review comment:
   These changes are unrelated, small PRs are better for reviewers ;-)

##
File path: src/main/java/org/apache/commons/collections4/IterableUtils.java
##
@@ -554,6 +555,34 @@
 };
 }
 
+/**
+ * Provides iteration over the elements contained in a pair of Iterables 
in-tandem.
+ * 
+ * The returned iterable has an iterator that traverses the elements in 
{@code a}
+ * and {@code b} together until one of the iterables is traversed 
completely.
+ * 
+ * The returned iterable's iterator does NOT support {@code remove()}.
+ *
+ * @param  the left elements' type
+ * @param  the right elements' type
+ * @param left the iterable for the left side elements
+ * @param right the iterable for the right side elements
+ * @return an iterable, over the decorated iterables to traverse them 
together until one is
+ * exhausted
+ * @throws NullPointerException if any iterator is null
+ */

Review comment:
   New public and protected method should have `@since 4.5` Javadoc tags.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-collections] garydgregory commented on a change in pull request #238: [COLLECTIONS-795] Add a new Iterator to allowing zipping over two iterators of different types

2021-06-01 Thread GitBox


garydgregory commented on a change in pull request #238:
URL: 
https://github.com/apache/commons-collections/pull/238#discussion_r643425608



##
File path: 
src/main/java/org/apache/commons/collections4/iterators/PairedIterator.java
##
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.iterators;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+/**
+ * Provides a iteration over the elements contained in a pair of Iterators.
+ *
+ * 
+ * Given two {@link Iterator} instances {@code A} and {@code B}, the {@link 
#next} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one 
of the iterators is
+ * exhausted.
+ * 
+ * Example usage:
+ * {@code
+ *   List studentIds = ...
+ *   List studentNames = ...
+ *
+ *   PairedIterator> pairedIterator =
+ * PairedIterator.ofIterables(studentIds, studentNames);
+ *
+ *   while (pairedIterator.hasNext()) {
+ * PairedItem item = zippedIterator.next();
+ * ...
+ *   }
+ * }
+ *
+ * @param  the left elements' type
+ * @param  the right elements' type
+ */
+public class PairedIterator implements Iterator> {
+
+/**
+ * The left {@link Iterator}s to evaluate.
+ */
+private final Iterator leftIterator;
+
+/**
+ * The right {@link Iterator}s to evaluate.
+ */
+private final Iterator rightIterator;
+
+// Constructor
+// --
+
+/**
+ * Constructs a new {@code ZipPairIterator} that will provide  iteration 
over the two given
+ * iterators.
+ *
+ * @param leftIterator  the iterator for the left side element.
+ * @param rightIterator the iterator for the right side element.
+ * @throws NullPointerException if either iterator is null
+ */
+public PairedIterator(Iterator leftIterator, Iterator rightIterator) 
{
+this.leftIterator = requireNonNull(leftIterator);
+this.rightIterator = requireNonNull(rightIterator);
+}
+
+/**
+ * Convenience static factory to construct the ZipPairIterator
+ *
+ * @param leftIterator  the iterator for the left side element.
+ * @param rightIterator the iterator for the right side element.
+ * @return the iterator to iterate over the provided iterators.
+ * @throws NullPointerException if either iterator is null
+ */
+public static  PairedIterator of(Iterator leftIterator, 
Iterator rightIterator) {
+return new PairedIterator<>(leftIterator, rightIterator);
+}
+
+/**
+ * Convenience static factory to construct the ZipPairIterator from any 
{@link Iterable} sources.
+ *
+ * @param leftIterable  the iterable for the left side element.
+ * @param rightIterable the iterable for the right side element.
+ * @return the iterator to iterate over the iterators derived from the 
provided iterables.
+ * @throws NullPointerException if either iterables is null
+ */
+public static  PairedIterator ofIterables(Iterable 
leftIterable, Iterable rightIterable) {
+return of(requireNonNull(leftIterable).iterator(), 
requireNonNull(rightIterable).iterator());
+}
+
+// Iterator Methods
+// ---
+
+/**
+ * Returns {@code true} if both the child iterators have remaining 
elements.
+ *
+ * @return true if both the child iterators have remaining elements
+ */
+@Override
+public boolean hasNext() {
+return leftIterator.hasNext() && rightIterator.hasNext();
+}
+
+/**
+ * Returns the next elements from both the child iterators.
+ *
+ * @return the next elements from both the iterators.
+ * @throws NoSuchElementException if any one child iterator is exhausted.
+ */
+@Override
+public PairedItem next() {
+if (!hasNext()) {
+throw new NoSuchElementException();
+}
+
+return PairedItem.of(leftIterator.next(), rightIterator.next());

[GitHub] [commons-collections] garydgregory commented on a change in pull request #238: [COLLECTIONS-795] Add a new Iterator to allowing zipping over two iterators of different types

2021-05-26 Thread GitBox


garydgregory commented on a change in pull request #238:
URL: 
https://github.com/apache/commons-collections/pull/238#discussion_r640134632



##
File path: 
src/main/java/org/apache/commons/collections4/iterators/ZippedTupleIterator.java
##
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.iterators;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import 
org.apache.commons.collections4.iterators.ZippedTupleIterator.ZippedTuple;
+
+/**
+ * Provides a iteration over the elements contained in a pair of Iterators.
+ *
+ * 
+ * Given two {@link Iterator} instances {@code A} and {@code B}, the {@link 
#next} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one 
of the iterators is
+ * exhausted.
+ * 
+ * Example usage:
+ * {@code
+ *   List studentIds = ...
+ *   List studentNames = ...
+ *
+ *   ZippedTupleIterator> zippedIterator =
+ * ZippedTupleIterator.ofIterables(studentIds, studentNames);
+ *
+ *   while (zippedIterator.hasNext()) {
+ * ZippedTuple item = zippedIterator.next();
+ * ...
+ *   }
+ * }
+ *
+ * @param  the left elements' type
+ * @param  the right elements' type
+ */
+public class ZippedTupleIterator implements Iterator> {

Review comment:
   Maybe but the prefix here is "zipped" not "zipper", terrible name IMO.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-collections] garydgregory commented on a change in pull request #238: [COLLECTIONS-795] Add a new Iterator to allowing zipping over two iterators of different types

2021-05-26 Thread GitBox


garydgregory commented on a change in pull request #238:
URL: 
https://github.com/apache/commons-collections/pull/238#discussion_r640040301



##
File path: 
src/main/java/org/apache/commons/collections4/iterators/ZippedTupleIterator.java
##
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.iterators;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import 
org.apache.commons.collections4.iterators.ZippedTupleIterator.ZippedTuple;
+
+/**
+ * Provides a iteration over the elements contained in a pair of Iterators.
+ *
+ * 
+ * Given two {@link Iterator} instances {@code A} and {@code B}, the {@link 
#next} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one 
of the iterators is
+ * exhausted.
+ * 
+ * Example usage:
+ * {@code
+ *   List studentIds = ...
+ *   List studentNames = ...
+ *
+ *   ZippedTupleIterator> zippedIterator =
+ * ZippedTupleIterator.ofIterables(studentIds, studentNames);
+ *
+ *   while (zippedIterator.hasNext()) {
+ * ZippedTuple item = zippedIterator.next();
+ * ...
+ *   }
+ * }
+ *
+ * @param  the left elements' type
+ * @param  the right elements' type
+ */
+public class ZippedTupleIterator implements Iterator> {

Review comment:
   Why is this prefixed with "zip" when it has nothing to do with zip files?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org