You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "anantdamle (via GitHub)" <gi...@apache.org> on 2023/08/14 12:21:55 UTC
[GitHub] [commons-collections] anantdamle opened a new pull request, #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
anantdamle opened a new pull request, #412:
URL: https://github.com/apache/commons-collections/pull/412
[COLLECTIONS-795] Add a new Iterator to allowing zipping over two iterators of different types
This is different from ZippingIterator which only permits sub-iterators of same type.
Created as #238 was overwhelmed with multiple commits due to inactivity for 2+ years.
@garydgregory can you please consider this proposal
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] anantdamle commented on pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on PR #412:
URL: https://github.com/apache/commons-collections/pull/412#issuecomment-1700363964
@Claudenw thanks for reviewing this, fixed checkstyle formatting issues.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] Claudenw commented on a diff in pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "Claudenw (via GitHub)" <gi...@apache.org>.
Claudenw commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1306962236
##########
src/main/java/org/apache/commons/collections4/IteratorUtils.java:
##########
@@ -30,38 +30,7 @@
import java.util.Objects;
import org.apache.commons.collections4.functors.EqualPredicate;
-import org.apache.commons.collections4.iterators.ArrayIterator;
-import org.apache.commons.collections4.iterators.ArrayListIterator;
-import org.apache.commons.collections4.iterators.BoundedIterator;
-import org.apache.commons.collections4.iterators.CollatingIterator;
-import org.apache.commons.collections4.iterators.EmptyIterator;
-import org.apache.commons.collections4.iterators.EmptyListIterator;
-import org.apache.commons.collections4.iterators.EmptyMapIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedMapIterator;
-import org.apache.commons.collections4.iterators.EnumerationIterator;
-import org.apache.commons.collections4.iterators.FilterIterator;
-import org.apache.commons.collections4.iterators.FilterListIterator;
-import org.apache.commons.collections4.iterators.IteratorChain;
-import org.apache.commons.collections4.iterators.IteratorEnumeration;
-import org.apache.commons.collections4.iterators.IteratorIterable;
-import org.apache.commons.collections4.iterators.ListIteratorWrapper;
-import org.apache.commons.collections4.iterators.LoopingIterator;
-import org.apache.commons.collections4.iterators.LoopingListIterator;
-import org.apache.commons.collections4.iterators.NodeListIterator;
-import org.apache.commons.collections4.iterators.ObjectArrayIterator;
-import org.apache.commons.collections4.iterators.ObjectArrayListIterator;
-import org.apache.commons.collections4.iterators.ObjectGraphIterator;
-import org.apache.commons.collections4.iterators.PeekingIterator;
-import org.apache.commons.collections4.iterators.PushbackIterator;
-import org.apache.commons.collections4.iterators.SingletonIterator;
-import org.apache.commons.collections4.iterators.SingletonListIterator;
-import org.apache.commons.collections4.iterators.SkippingIterator;
-import org.apache.commons.collections4.iterators.TransformIterator;
-import org.apache.commons.collections4.iterators.UnmodifiableIterator;
-import org.apache.commons.collections4.iterators.UnmodifiableListIterator;
-import org.apache.commons.collections4.iterators.UnmodifiableMapIterator;
-import org.apache.commons.collections4.iterators.ZippingIterator;
+import org.apache.commons.collections4.iterators.*;
Review Comment:
Do not replace individual imports with start '*' imports
##########
src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java:
##########
@@ -46,16 +46,7 @@
import java.util.Set;
import java.util.Vector;
-import org.apache.commons.collections4.iterators.ArrayIterator;
-import org.apache.commons.collections4.iterators.EmptyIterator;
-import org.apache.commons.collections4.iterators.EmptyListIterator;
-import org.apache.commons.collections4.iterators.EmptyMapIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedMapIterator;
-import org.apache.commons.collections4.iterators.EnumerationIterator;
-import org.apache.commons.collections4.iterators.NodeListIterator;
-import org.apache.commons.collections4.iterators.ObjectArrayIterator;
-import org.apache.commons.collections4.iterators.ZippingIterator;
+import org.apache.commons.collections4.iterators.*;
Review Comment:
Do not replace individual imports with start '*' imports
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on PR #412:
URL: https://github.com/apache/commons-collections/pull/412#issuecomment-2137624962
@garydgregory made changes as requested and rebased on latest master
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] Claudenw commented on pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "Claudenw (via GitHub)" <gi...@apache.org>.
Claudenw commented on PR #412:
URL: https://github.com/apache/commons-collections/pull/412#issuecomment-1695090648
@anantdamle I had a professor who stated there are only 3 valid limits in computing: zero, one, and many. Your solution zips two iterators, have you considered who to generalize that to many? Is that possible?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] anantdamle commented on pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on PR #412:
URL: https://github.com/apache/commons-collections/pull/412#issuecomment-1695155262
> @anantdamle I had a professor who stated there are only 3 valid limits in computing: zero, one, and many. Your solution zips two iterators, have you considered who to generalize that to many? Is that possible?
I think Its possible, and I have tried it, with a working prototype, though the interface becomes too complex as the consitutents can be of different kind (classes), so will have to use Object and class type, which in my opinion becomes a bad design.
```
class MultiZipIterator implements Iterator<List<Pair<Object, Class>>>
````
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1619036729
##########
src/test/java/org/apache/commons/collections4/PairedIterableTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.stream.IntStream;
+
+import static java.util.Collections.unmodifiableList;
+import static java.util.stream.Collectors.toList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+@RunWith(Enclosed.class)
+public final class PairedIterableTest {
+
+ private static final int SMALL_LIST_SIZE = 20;
+ private static final int LARGE_LIST_SIZE = 40;
+
+ private static final List<String> SMALL_STRINGS_LIST =
+ unmodifiableList(stringsList(SMALL_LIST_SIZE));
Review Comment:
Done
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1617306617
##########
src/main/java/org/apache/commons/collections4/PairedIterable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+import java.util.Iterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Provides iteration over the elements contained in a pair of Iterables in-tandem.
+ *
+ * <p>
+ * Given two {@link Iterable} instances {@code A} and {@code B}, the {@link #iterator} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one of the iterators is
+ * exhausted.
+ * </p>
+ * This can simplify zipping over two iterables using the for-each construct.
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * for (PairedItem<Integer, String> items : PairedIterable.of(studentIds, studentNames) {
+ * Integer studentId = item.getLeft();
+ * String studentName = item.getRight();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
+public class PairedIterable<L, R> implements Iterable<PairedItem<L, R>> {
+
+ /**
+ * The left {@link Iterable}s to evaluate.
+ */
+ private final Iterable<L> leftIterable;
+
+ /**
+ * The right {@link Iterable}s to evaluate.
+ */
+ private final Iterable<R> rightIterable;
+
+ // Constructor
+ // ----------------------------------------------------------------------
+
+ /**
+ * Constructs a new {@code PairedIterable} that will provide iteration over two given iterables.
+ *
+ * @param leftIterable the iterable for the left side element.
+ * @param rightIterable the iterable for the right side element.
+ * @throws NullPointerException if either iterator is null
+ */
+ public PairedIterable(Iterable<L> leftIterable, Iterable<R> rightIterable) {
+ this.leftIterable = requireNonNull(leftIterable);
+ this.rightIterable = requireNonNull(rightIterable);
+ }
+
+ /**
+ * Convenience static factory to construct the PairedIterable from provided
+ * {@link Iterable} sources.
+ *
+ * @param leftIterable the iterable for the left side element.
+ * @param rightIterable the iterable for the right side element.
+ * @return the Iterable to iterate over the elements derived from the provided iterables.
+ * @throws NullPointerException if either iterables is null
+ */
+ public static <L, R> PairedIterable<L, R> of(Iterable<L> leftIterable, Iterable<R> rightIterable) {
+ return new PairedIterable<>(leftIterable, rightIterable);
+ }
+
+ // Iterable Methods
+ // -------------------------------------------------------------------
+
+ @Override
+ public Iterator<PairedItem<L, R>> iterator() {
+ return PairedIterator.ofIterables(leftIterable, rightIterable);
+ }
+
+ public Stream<PairedItem<L, R>> stream() {
+ return StreamSupport.stream(spliterator(), /*parallel=*/ false);
Review Comment:
Don't comment arguments.
##########
src/main/java/org/apache/commons/collections4/PairedIterable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+import java.util.Iterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Provides iteration over the elements contained in a pair of Iterables in-tandem.
+ *
+ * <p>
+ * Given two {@link Iterable} instances {@code A} and {@code B}, the {@link #iterator} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one of the iterators is
+ * exhausted.
+ * </p>
+ * This can simplify zipping over two iterables using the for-each construct.
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * for (PairedItem<Integer, String> items : PairedIterable.of(studentIds, studentNames) {
+ * Integer studentId = item.getLeft();
+ * String studentName = item.getRight();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
Review Comment:
New public and protected elements need Javadoc `since` tags.
##########
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.
+ *
+ * <p>
+ * 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.
+ * </p>
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * PairedIterator<PairedItem<Integer, String>> pairedIterator =
+ * PairedIterator.ofIterables(studentIds, studentNames);
+ *
+ * while (pairedIterator.hasNext()) {
+ * PairedItem<Integer, String> item = zippedIterator.next();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
+public class PairedIterator<L, R> implements Iterator<PairedItem<L, R>> {
+
+ /**
+ * The left {@link Iterator}s to evaluate.
+ */
+ private final Iterator<L> leftIterator;
+
+ /**
+ * The right {@link Iterator}s to evaluate.
+ */
+ private final Iterator<R> 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<L> leftIterator, Iterator<R> 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 <L, R> PairedIterator<L, R> of(Iterator<L> leftIterator, Iterator<R> 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 <L, R> PairedIterator<L, R> ofIterables(Iterable<L> leftIterable, Iterable<R> 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<L, R> next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
Review Comment:
No need for extra whitespace.
##########
src/main/java/org/apache/commons/collections4/PairedIterable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+import java.util.Iterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Provides iteration over the elements contained in a pair of Iterables in-tandem.
+ *
+ * <p>
+ * Given two {@link Iterable} instances {@code A} and {@code B}, the {@link #iterator} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one of the iterators is
+ * exhausted.
+ * </p>
+ * This can simplify zipping over two iterables using the for-each construct.
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * for (PairedItem<Integer, String> items : PairedIterable.of(studentIds, studentNames) {
+ * Integer studentId = item.getLeft();
+ * String studentName = item.getRight();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
+public class PairedIterable<L, R> implements Iterable<PairedItem<L, R>> {
+
+ /**
+ * The left {@link Iterable}s to evaluate.
+ */
+ private final Iterable<L> leftIterable;
+
+ /**
+ * The right {@link Iterable}s to evaluate.
+ */
+ private final Iterable<R> rightIterable;
+
+ // Constructor
+ // ----------------------------------------------------------------------
+
+ /**
+ * Constructs a new {@code PairedIterable} that will provide iteration over two given iterables.
+ *
+ * @param leftIterable the iterable for the left side element.
+ * @param rightIterable the iterable for the right side element.
+ * @throws NullPointerException if either iterator is null
+ */
+ public PairedIterable(Iterable<L> leftIterable, Iterable<R> rightIterable) {
+ this.leftIterable = requireNonNull(leftIterable);
+ this.rightIterable = requireNonNull(rightIterable);
+ }
+
+ /**
+ * Convenience static factory to construct the PairedIterable from provided
+ * {@link Iterable} sources.
+ *
+ * @param leftIterable the iterable for the left side element.
+ * @param rightIterable the iterable for the right side element.
+ * @return the Iterable to iterate over the elements derived from the provided iterables.
+ * @throws NullPointerException if either iterables is null
+ */
+ public static <L, R> PairedIterable<L, R> of(Iterable<L> leftIterable, Iterable<R> rightIterable) {
+ return new PairedIterable<>(leftIterable, rightIterable);
+ }
+
+ // Iterable Methods
Review Comment:
Don't use these types of comments, just sort the methods in AB order.
##########
src/test/java/org/apache/commons/collections4/PairedIterableTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.stream.IntStream;
+
+import static java.util.Collections.unmodifiableList;
+import static java.util.stream.Collectors.toList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+@RunWith(Enclosed.class)
+public final class PairedIterableTest {
+
+ private static final int SMALL_LIST_SIZE = 20;
+ private static final int LARGE_LIST_SIZE = 40;
+
+ private static final List<String> SMALL_STRINGS_LIST =
+ unmodifiableList(stringsList(SMALL_LIST_SIZE));
Review Comment:
Use longer lines.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1618969114
##########
src/main/java/org/apache/commons/collections4/PairedIterable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+import java.util.Iterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Provides iteration over the elements contained in a pair of Iterables in-tandem.
+ *
+ * <p>
+ * Given two {@link Iterable} instances {@code A} and {@code B}, the {@link #iterator} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one of the iterators is
+ * exhausted.
+ * </p>
+ * This can simplify zipping over two iterables using the for-each construct.
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * for (PairedItem<Integer, String> items : PairedIterable.of(studentIds, studentNames) {
+ * Integer studentId = item.getLeft();
+ * String studentName = item.getRight();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
Review Comment:
what version value should I use for @since tag?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1618978461
##########
src/main/java/org/apache/commons/collections4/PairedIterable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+import java.util.Iterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Provides iteration over the elements contained in a pair of Iterables in-tandem.
+ *
+ * <p>
+ * Given two {@link Iterable} instances {@code A} and {@code B}, the {@link #iterator} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one of the iterators is
+ * exhausted.
+ * </p>
+ * This can simplify zipping over two iterables using the for-each construct.
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * for (PairedItem<Integer, String> items : PairedIterable.of(studentIds, studentNames) {
+ * Integer studentId = item.getLeft();
+ * String studentName = item.getRight();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
Review Comment:
should I use `@since 4.5`
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on PR #412:
URL: https://github.com/apache/commons-collections/pull/412#issuecomment-2292737470
Gentle bump up for review
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] anantdamle commented on a diff in pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1306994422
##########
src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java:
##########
@@ -46,16 +46,7 @@
import java.util.Set;
import java.util.Vector;
-import org.apache.commons.collections4.iterators.ArrayIterator;
-import org.apache.commons.collections4.iterators.EmptyIterator;
-import org.apache.commons.collections4.iterators.EmptyListIterator;
-import org.apache.commons.collections4.iterators.EmptyMapIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedMapIterator;
-import org.apache.commons.collections4.iterators.EnumerationIterator;
-import org.apache.commons.collections4.iterators.NodeListIterator;
-import org.apache.commons.collections4.iterators.ObjectArrayIterator;
-import org.apache.commons.collections4.iterators.ZippingIterator;
+import org.apache.commons.collections4.iterators.*;
Review Comment:
Thanks, Fixed.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] anantdamle commented on a diff in pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1306994780
##########
src/main/java/org/apache/commons/collections4/IteratorUtils.java:
##########
@@ -30,38 +30,7 @@
import java.util.Objects;
import org.apache.commons.collections4.functors.EqualPredicate;
-import org.apache.commons.collections4.iterators.ArrayIterator;
-import org.apache.commons.collections4.iterators.ArrayListIterator;
-import org.apache.commons.collections4.iterators.BoundedIterator;
-import org.apache.commons.collections4.iterators.CollatingIterator;
-import org.apache.commons.collections4.iterators.EmptyIterator;
-import org.apache.commons.collections4.iterators.EmptyListIterator;
-import org.apache.commons.collections4.iterators.EmptyMapIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedIterator;
-import org.apache.commons.collections4.iterators.EmptyOrderedMapIterator;
-import org.apache.commons.collections4.iterators.EnumerationIterator;
-import org.apache.commons.collections4.iterators.FilterIterator;
-import org.apache.commons.collections4.iterators.FilterListIterator;
-import org.apache.commons.collections4.iterators.IteratorChain;
-import org.apache.commons.collections4.iterators.IteratorEnumeration;
-import org.apache.commons.collections4.iterators.IteratorIterable;
-import org.apache.commons.collections4.iterators.ListIteratorWrapper;
-import org.apache.commons.collections4.iterators.LoopingIterator;
-import org.apache.commons.collections4.iterators.LoopingListIterator;
-import org.apache.commons.collections4.iterators.NodeListIterator;
-import org.apache.commons.collections4.iterators.ObjectArrayIterator;
-import org.apache.commons.collections4.iterators.ObjectArrayListIterator;
-import org.apache.commons.collections4.iterators.ObjectGraphIterator;
-import org.apache.commons.collections4.iterators.PeekingIterator;
-import org.apache.commons.collections4.iterators.PushbackIterator;
-import org.apache.commons.collections4.iterators.SingletonIterator;
-import org.apache.commons.collections4.iterators.SingletonListIterator;
-import org.apache.commons.collections4.iterators.SkippingIterator;
-import org.apache.commons.collections4.iterators.TransformIterator;
-import org.apache.commons.collections4.iterators.UnmodifiableIterator;
-import org.apache.commons.collections4.iterators.UnmodifiableListIterator;
-import org.apache.commons.collections4.iterators.UnmodifiableMapIterator;
-import org.apache.commons.collections4.iterators.ZippingIterator;
+import org.apache.commons.collections4.iterators.*;
Review Comment:
Thanks, Fixed.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-collections] anantdamle commented on pull request #412: [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on PR #412:
URL: https://github.com/apache/commons-collections/pull/412#issuecomment-1695148787
also fixed it in `PairedIterableTest.java`
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COLLECTIONS-795] Add PairedIterator to allow iterating over different-types of iterators [commons-collections]
Posted by "anantdamle (via GitHub)" <gi...@apache.org>.
anantdamle commented on code in PR #412:
URL: https://github.com/apache/commons-collections/pull/412#discussion_r1618969114
##########
src/main/java/org/apache/commons/collections4/PairedIterable.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import org.apache.commons.collections4.iterators.PairedIterator;
+import org.apache.commons.collections4.iterators.PairedIterator.PairedItem;
+
+import java.util.Iterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Provides iteration over the elements contained in a pair of Iterables in-tandem.
+ *
+ * <p>
+ * Given two {@link Iterable} instances {@code A} and {@code B}, the {@link #iterator} method on this
+ * iterator provide a Pair of {@code A.next()} and {@code B.next()} until one of the iterators is
+ * exhausted.
+ * </p>
+ * This can simplify zipping over two iterables using the for-each construct.
+ * Example usage:
+ * <pre>{@code
+ * List<Integer> studentIds = ...
+ * List<String> studentNames = ...
+ *
+ * for (PairedItem<Integer, String> items : PairedIterable.of(studentIds, studentNames) {
+ * Integer studentId = item.getLeft();
+ * String studentName = item.getRight();
+ * ...
+ * }
+ * }</pre>
+ *
+ * @param <L> the left elements' type
+ * @param <R> the right elements' type
+ */
Review Comment:
what version value should I use for `since` tag?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org