-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[COLLECTIONS-858] Add CartesianProductIterator #509
[COLLECTIONS-858] Add CartesianProductIterator #509
Conversation
a5e554d
to
003f60a
Compare
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Show resolved
Hide resolved
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Outdated
Show resolved
Hide resolved
003f60a
to
c160cc1
Compare
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
c160cc1
to
6508495
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good apart from the javadoc which will fail the build. If you use <,>
chars you need a code tag.
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Outdated
Show resolved
Hide resolved
6508495
to
9ef6055
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #509 +/- ##
============================================
- Coverage 81.60% 81.53% -0.08%
- Complexity 4745 4848 +103
============================================
Files 295 301 +6
Lines 13751 14128 +377
Branches 2022 2078 +56
============================================
+ Hits 11222 11519 +297
- Misses 1929 1995 +66
- Partials 600 614 +14 ☔ View full report in Codecov by Sentry. |
9ef6055
to
4a44380
Compare
@alexey-pelykh |
4a44380
to
9b5791b
Compare
@garydgregory sorry, my oversight - should be green now |
@garydgregory would it be possible to restart 23-ae? It's not exactly clear what is wrong |
The build died at the PMD plugin with an unsupported class major version number of 67 (for Java 23). However the build on 23 is allowed to fail as it is in the experimental group in the workflow: maven.yml This looks good to me. |
What would be the next steps? |
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Show resolved
Hide resolved
9b5791b
to
043a5d4
Compare
@alexey-pelykh |
@garydgregory that is true, any specific requirements what to write there apart of what I've already added to it? Edit: I truly don't know what else to write, the name of the PR is self-explanatory really. It's a new iterator that implements a cartesian product, which is literally a nested for-loop yet writing a manual for loop when there's 10-25-50 depth would be troublesome. |
@alexey-pelykh |
@garydgregory okies, done 👍 |
Seems not much of a discussion :) |
👋 @garydgregory anything I can do to push this forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @alexey-pelykh
- You are missing a unit test for Iterator.forEachRemaining()
- Also edge cases like what if the first list, a middle list or the last list is empty.
- IOW what is the expected behavior if in your example
letters
,numbers
, orsymbols
is empty - What should happen if the lists point to each other or have cycles?
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/collections4/iterators/CartesianProductIteratorTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/collections4/iterators/CartesianProductIterator.java
Outdated
Show resolved
Hide resolved
Hi @garydgregory:
What is the rationale to add that given that
Reasonable, added.
Added tests to be explicit. If at least one list is empty, cartesian product returns no tuples.
If any of the passed iterables has cycle and thus is infinite, the iterator would also produce an infinite result. Here the behavior is the same as in nested for-loop. Could you please elaborate on the lists pointing to each other case as I'm not exactly sure I got you there. |
f6f11c2
to
974feca
Compare
974feca
to
3706572
Compare
If the API allows an infinite loop, this is what will happen: Someone will send an email to our security mailing list saying they found a critical DOS vulnerability and ask for a CVE to be credited to them; time will be taken analyzing, deciding what to do and replying to the poster. This is why we've fixed these types of bugs overtime and added tests like:
And yes, there are probably more of these types of bugs lurking around, so let's not add new ones ;-) |
0455fb8
to
da55fb0
Compare
Absolutely not my intent! That said, I guess I'm too dumb to understand how that bug may be exploited in this case.
However, the infinite loop won't happen in the |
EA builds are marked experimental in the CI and fail when the tooling has not been adapted Java EA versions. In this case PMD needs an update to ASM to support Java 23 and 24 byte code changes. If your branch fails with the same errors as |
The new class implements an interface. The tests should show what are the expectations for all interface methods, the ones that are actually implemented by the new class and the behavior that is inherited from the default method. There is no guarantee that implementing the methods that a default interface calls is actually correctly implementing the contract for the default method. Testing the default methods shows that it works as expected, regardless of whether the default method is implemented or inherited. You are also showing as a PR author that you've considered the big picture and are thorough, all the pieces work individually and together, as expected. |
da55fb0
to
3ec24ed
Compare
👍 test added |
Thank you for your PR and patience. Merged! 🚀 |
The
CartesianProductIterator
is suitable to enhance a deeply-nested for-loops over a set of collections.Given
instead of
it would look like:
Extremely useful for nesting levels 10+.