-
Notifications
You must be signed in to change notification settings - Fork 48
Introduce {Flux,Stream}DistinctSort{,ed}{,WithComparator} Refaster rules
#1950
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
base: master
Are you sure you want to change the base?
Conversation
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.
Added one commit with some tweaks. Thanks @copilot!
Suggested commit message:
Introduce `{Flux,Stream}DistinctSort{,ed}{,WithComparator}` Refaster rules (#1950)
While there, simplify some unrelated test cases.
Resolves #1828.
{Flux,String}DistinctSort{,ed}{,WithComparator} Refaster rules
{Flux,String}DistinctSort{,ed}{,WithComparator} Refaster rules{Flux,Stream}DistinctSort{,ed}{,WithComparator} Refaster rules
|
Looks good. No mutations were possible for these changes. |
|
To be merged after #1942. |
mohamedsamehsalah
left a comment
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.
Thanks @Stephan202 and @copilot! 🚀
| } | ||
|
|
||
| Flux<Integer> testFluxFilterSort() { | ||
| return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); |
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.
😄 : I'd say "A for for effort" 👏
- Add StreamDistinctSorted rule to rewrite stream.sorted().distinct() → stream.distinct().sorted() - Add StreamDistinctSortedWithComparator rule for comparator overload - Add FluxDistinctSort rule to rewrite flux.sort().distinct() → flux.distinct().sort() - Add FluxDistinctSortWithComparator rule for comparator overload - Add test cases for all new rules in TestInput and TestOutput files Co-authored-by: Stephan202 <[email protected]>
63f6131 to
23c7e50
Compare
|
Looks good. No mutations were possible for these changes. |
|



Sorting data that will be largely discarded by a subsequent distinct operation wastes cycles. Applying distinct first reduces the element count before the expensive sort.
Changes
StreamRules.java
StreamDistinctSorted:stream.sorted().distinct()→stream.distinct().sorted()StreamDistinctSortedWithComparator:stream.sorted(comparator).distinct()→stream.distinct().sorted(comparator)ReactorRules.java
FluxDistinctSort:flux.sort().distinct()→flux.distinct().sort()FluxDistinctSortWithComparator:flux.sort(comparator).distinct()→flux.distinct().sort(comparator)Test coverage
Added test cases in
StreamRulesTestInput/Output.javaandReactorRulesTestInput/Output.javaExample
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
checkstyle.org/opt/hostedtoolcache/CodeQL/2.23.3/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.3/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/error-prone-support/.codeql-scratch/dbs/java/working/files-to-index3342103831160680863.list --sourceArchiveDir=/home/REDACTED/work/error-prone-support/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/error-prone-support/.codeql-scratch/dbs/java/trap/java(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.