Introduce {Flux,Stream}DistinctSort{,ed}{,WithComparator} Refaster rules#1950
Introduce {Flux,Stream}DistinctSort{,ed}{,WithComparator} Refaster rules#1950Stephan202 merged 2 commits intomasterfrom
{Flux,Stream}DistinctSort{,ed}{,WithComparator} Refaster rules#1950Conversation
There was a problem hiding this comment.
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.
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.
😄 : I'd say "A for for effort" 👏
63f6131 to
23c7e50
Compare
|
Looks good. No mutations were possible for these changes. |
- 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 <513280+Stephan202@users.noreply.github.com>
23c7e50 to
349647b
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.