From d0af374cdcc193f40982c15c3b82f9ddfb96bf1f Mon Sep 17 00:00:00 2001 From: CoolTomatos <24667806+CoolTomatos@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:43:46 +0100 Subject: [PATCH 1/5] Refaster rules that encourage filtering before sorting. Closes PicnicSupermarket/error-prone-support#386. --- .../refasterrules/DoubleStreamRules.java | 13 +++++++++ .../refasterrules/IntStreamRules.java | 13 +++++++++ .../refasterrules/LongStreamRules.java | 13 +++++++++ .../refasterrules/ReactorRules.java | 28 ++++++++++++++++++ .../errorprone/refasterrules/StreamRules.java | 29 +++++++++++++++++++ .../DoubleStreamRulesTestInput.java | 4 +++ .../DoubleStreamRulesTestOutput.java | 4 +++ .../IntStreamRulesTestInput.java | 4 +++ .../IntStreamRulesTestOutput.java | 4 +++ .../LongStreamRulesTestInput.java | 4 +++ .../LongStreamRulesTestOutput.java | 4 +++ .../refasterrules/ReactorRulesTestInput.java | 11 +++++++ .../refasterrules/ReactorRulesTestOutput.java | 10 +++++++ .../refasterrules/StreamRulesTestInput.java | 11 +++++++ .../refasterrules/StreamRulesTestOutput.java | 11 +++++++ 15 files changed, 163 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java index ca64f929d8..2d8cb27278 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java @@ -141,6 +141,19 @@ DoubleStream after(Stream stream, DoubleFunction func } } + /** Apply filtering before sorting to reduce the number of elements to sort. */ + static final class SortAfterFilter { + @BeforeTemplate + DoubleStream before(DoubleStream stream, DoublePredicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + DoubleStream after(DoubleStream stream, DoublePredicate predicate) { + return stream.filter(predicate).sorted(); + } + } + /** In order to test whether a stream has any element, simply try to find one. */ static final class DoubleStreamIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java index 2c43fc3cc1..d61bd9e9a5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java @@ -154,6 +154,19 @@ IntStream after(Stream stream, IntFunction function) { } } + /** Apply filtering before sorting to reduce the number of elements to sort. */ + static final class SortAfterFilter { + @BeforeTemplate + IntStream before(IntStream stream, IntPredicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + IntStream after(IntStream stream, IntPredicate predicate) { + return stream.filter(predicate).sorted(); + } + } + /** In order to test whether a stream has any element, simply try to find one. */ static final class IntStreamIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java index 363157c55f..a5eefa9181 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java @@ -154,6 +154,19 @@ LongStream after(Stream stream, LongFunction function) } } + /** Apply filtering before sorting to reduce the number of elements to sort. */ + static final class SortAfterFilter { + @BeforeTemplate + LongStream before(LongStream stream, LongPredicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + LongStream after(LongStream stream, LongPredicate predicate) { + return stream.filter(predicate).sorted(); + } + } + /** In order to test whether a stream has any element, simply try to find one. */ static final class LongStreamIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 6b6997a5ed..c1ea1b44da 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -17,6 +17,7 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.time.Duration; +import java.util.Comparator; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; @@ -1246,4 +1247,31 @@ Duration after(StepVerifier.LastStep step, Duration duration) { return step.verifyTimeout(duration); } } + + /** Apply filtering before sorting to reduce the number of elements to sort. */ + static final class SortAfterFilter { + @BeforeTemplate + Flux before(Flux flux, Predicate predicate) { + return flux.sort().filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate) { + return flux.filter(predicate).sort(); + } + } + + /** Apply filtering before sorting with a comparator to reduce the number of elements to sort. */ + abstract static class SortWithComparatorAfterFilter { + @BeforeTemplate + Flux before( + Flux flux, Predicate predicate, Comparator comparator) { + return flux.sort(comparator).filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate, Comparator comparator) { + return flux.filter(predicate).sort(comparator); + } + } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 322f232831..2ad0096f42 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -167,6 +167,35 @@ Stream after(Stream stream, Function { + @BeforeTemplate + Stream before(Stream stream, Predicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + Stream after(Stream stream, Predicate predicate) { + return stream.filter(predicate).sorted(); + } + } + + /** Apply filter before sorting with a comparator to reduce the number of elements to sort. */ + abstract static class SortWithComparatorAfterFilter { + @BeforeTemplate + Stream before( + Stream stream, Predicate predicate, Comparator comparator) { + return stream.sorted(comparator).filter(predicate); + } + + @AfterTemplate + Stream after( + Stream stream, Predicate predicate, Comparator comparator) { + return stream.filter(predicate).sorted(comparator); + } + } + + /** * Where possible, clarify that a mapping operation will be applied only to a single stream * element. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java index 9c35f9c651..da75410ab9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java @@ -46,6 +46,10 @@ DoubleStream testFlatMapOuterStreamAfterFlatMapToDouble() { return Stream.of(1).flatMapToDouble(v -> DoubleStream.of(v * v).flatMap(DoubleStream::of)); } + DoubleStream testSortAfterFilter() { + return DoubleStream.of(1, 4, 3, 2).sorted().filter(d -> d % 2 == 0); + } + ImmutableSet testDoubleStreamIsEmpty() { return ImmutableSet.of( DoubleStream.of(1).count() == 0, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java index 0f5c7db8eb..143096c684 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java @@ -46,6 +46,10 @@ DoubleStream testFlatMapOuterStreamAfterFlatMapToDouble() { return Stream.of(1).flatMapToDouble(v -> DoubleStream.of(v * v)).flatMap(DoubleStream::of); } + DoubleStream testSortAfterFilter() { + return DoubleStream.of(1, 4, 3, 2).filter(d -> d % 2 == 0).sorted(); + } + ImmutableSet testDoubleStreamIsEmpty() { return ImmutableSet.of( DoubleStream.of(1).findAny().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java index 32458e2bbb..dcd2b23168 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java @@ -50,6 +50,10 @@ IntStream testFlatMapOuterStreamAfterFlatMapToInt() { return Stream.of(1).flatMapToInt(v -> IntStream.of(v * v).flatMap(IntStream::of)); } + IntStream testSortAfterFilter() { + return IntStream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); + } + ImmutableSet testIntStreamIsEmpty() { return ImmutableSet.of( IntStream.of(1).count() == 0, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java index c75ce7bb7f..ceeb22adb9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java @@ -50,6 +50,10 @@ IntStream testFlatMapOuterStreamAfterFlatMapToInt() { return Stream.of(1).flatMapToInt(v -> IntStream.of(v * v)).flatMap(IntStream::of); } + IntStream testSortAfterFilter() { + return IntStream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); + } + ImmutableSet testIntStreamIsEmpty() { return ImmutableSet.of( IntStream.of(1).findAny().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java index 3909ce3df7..a5727de9f9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java @@ -50,6 +50,10 @@ LongStream testFlatMapOuterStreamAfterFlatMapToLong() { return Stream.of(1).flatMapToLong(v -> LongStream.of(v * v).flatMap(LongStream::of)); } + LongStream testSortAfterFilter() { + return LongStream.of(1, 4, 3, 2).sorted().filter(l -> l % 2 == 0); + } + ImmutableSet testLongStreamIsEmpty() { return ImmutableSet.of( LongStream.of(1).count() == 0, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java index b585534a33..198bb98b8e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java @@ -50,6 +50,10 @@ LongStream testFlatMapOuterStreamAfterFlatMapToLong() { return Stream.of(1).flatMapToLong(v -> LongStream.of(v * v)).flatMap(LongStream::of); } + LongStream testSortAfterFilter() { + return LongStream.of(1, 4, 3, 2).filter(l -> l % 2 == 0).sorted(); + } + ImmutableSet testLongStreamIsEmpty() { return ImmutableSet.of( LongStream.of(1).findAny().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index e256522c08..00e2b5a736 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; +import java.util.Comparator; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; @@ -385,4 +386,14 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).expectTimeout(Duration.ZERO).verify(); } + + Flux testSortAfterFilter() { + return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); + } + + Flux testSortWithComparatorAfterFilter() { + return Flux.just(1, 4, 3, 2) + .sort(Comparator.comparingInt(Integer::intValue).reversed()) + .filter(i -> i % 2 == 0); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 3c247811e4..db81f621aa 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -378,4 +378,14 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).verifyTimeout(Duration.ZERO); } + + Flux testSortAfterFilter() { + return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(); + } + + Flux testSortWithComparatorAfterFilter() { + return Flux.just(1, 4, 3, 2) + .filter(i -> i % 2 == 0) + .sort(Comparator.comparingInt(Integer::intValue).reversed()); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index 67911c452f..bcfe0fee8f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; +import java.util.Comparator; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -130,4 +131,14 @@ ImmutableSet testStreamAllMatch() { boolean testStreamAllMatch2() { return Stream.of("foo").noneMatch(s -> !s.isBlank()); } + + Stream testSortAfterFilter() { + return Stream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); + } + + Stream testSortWithComparatorAfterFilter() { + return Stream.of(1, 4, 3, 2) + .sorted(Comparator.comparingInt(Integer::intValue).reversed()) + .filter(i -> i % 2 == 0); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index 87e7619539..e91da0eb03 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import java.util.Arrays; +import java.util.Comparator; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -129,4 +130,14 @@ ImmutableSet testStreamAllMatch() { boolean testStreamAllMatch2() { return Stream.of("foo").allMatch(s -> s.isBlank()); } + + Stream testSortAfterFilter() { + return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); + } + + Stream testSortWithComparatorAfterFilter() { + return Stream.of(1, 4, 3, 2) + .filter(i -> i % 2 == 0) + .sorted(Comparator.comparingInt(Integer::intValue).reversed()); + } } From 69fa827be18ca198b2e64570062f250f823e10e0 Mon Sep 17 00:00:00 2001 From: CoolTomatos <24667806+CoolTomatos@users.noreply.github.com> Date: Tue, 6 Dec 2022 21:21:53 +0100 Subject: [PATCH 2/5] Fix the build. --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 5 ++--- .../tech/picnic/errorprone/refasterrules/StreamRules.java | 5 ++--- .../errorprone/refasterrules/ReactorRulesTestOutput.java | 1 + .../errorprone/refasterrules/StreamRulesTestInput.java | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index c1ea1b44da..a47d1c75a8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1262,10 +1262,9 @@ Flux after(Flux flux, Predicate predicate) { } /** Apply filtering before sorting with a comparator to reduce the number of elements to sort. */ - abstract static class SortWithComparatorAfterFilter { + static final class SortWithComparatorAfterFilter { @BeforeTemplate - Flux before( - Flux flux, Predicate predicate, Comparator comparator) { + Flux before(Flux flux, Predicate predicate, Comparator comparator) { return flux.sort(comparator).filter(predicate); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 2ad0096f42..68c4a53b21 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -168,7 +168,7 @@ Stream after(Stream stream, Function { + static final class SortAfterFilter { @BeforeTemplate Stream before(Stream stream, Predicate predicate) { return stream.sorted().filter(predicate); @@ -181,7 +181,7 @@ Stream after(Stream stream, Predicate predicate) { } /** Apply filter before sorting with a comparator to reduce the number of elements to sort. */ - abstract static class SortWithComparatorAfterFilter { + static final class SortWithComparatorAfterFilter { @BeforeTemplate Stream before( Stream stream, Predicate predicate, Comparator comparator) { @@ -195,7 +195,6 @@ Stream after( } } - /** * Where possible, clarify that a mapping operation will be applied only to a single stream * element. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index db81f621aa..46a942a0c1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; +import java.util.Comparator; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index bcfe0fee8f..4482d40470 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -138,7 +138,7 @@ Stream testSortAfterFilter() { Stream testSortWithComparatorAfterFilter() { return Stream.of(1, 4, 3, 2) - .sorted(Comparator.comparingInt(Integer::intValue).reversed()) - .filter(i -> i % 2 == 0); + .sorted(Comparator.comparingInt(Integer::intValue).reversed()) + .filter(i -> i % 2 == 0); } } From 95ab43293e95c60bf53bf8b27a97e3ce561833af Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 7 Dec 2022 19:28:46 +0100 Subject: [PATCH 3/5] Suggestions --- .../refasterrules/DoubleStreamRules.java | 7 +++++-- .../errorprone/refasterrules/IntStreamRules.java | 7 +++++-- .../errorprone/refasterrules/LongStreamRules.java | 7 +++++-- .../errorprone/refasterrules/ReactorRules.java | 14 ++++++++++---- .../errorprone/refasterrules/StreamRules.java | 14 ++++++++++---- .../refasterrules/DoubleStreamRulesTestInput.java | 2 +- .../refasterrules/DoubleStreamRulesTestOutput.java | 2 +- .../refasterrules/IntStreamRulesTestInput.java | 2 +- .../refasterrules/IntStreamRulesTestOutput.java | 2 +- .../refasterrules/LongStreamRulesTestInput.java | 2 +- .../refasterrules/LongStreamRulesTestOutput.java | 2 +- .../refasterrules/ReactorRulesTestInput.java | 10 ++++------ .../refasterrules/ReactorRulesTestOutput.java | 10 ++++------ .../refasterrules/StreamRulesTestInput.java | 11 ++++------- .../refasterrules/StreamRulesTestOutput.java | 11 ++++------- 15 files changed, 57 insertions(+), 46 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java index 2d8cb27278..ae8a389258 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java @@ -141,8 +141,11 @@ DoubleStream after(Stream stream, DoubleFunction func } } - /** Apply filtering before sorting to reduce the number of elements to sort. */ - static final class SortAfterFilter { + /** + * Apply {@link DoubleStream#filter(DoublePredicate)} before {@link DoubleStream#sorted()} to + * reduce the number of elements to sort. + */ + static final class DoubleStreamFilterSorted { @BeforeTemplate DoubleStream before(DoubleStream stream, DoublePredicate predicate) { return stream.sorted().filter(predicate); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java index d61bd9e9a5..679bddaa13 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java @@ -154,8 +154,11 @@ IntStream after(Stream stream, IntFunction function) { } } - /** Apply filtering before sorting to reduce the number of elements to sort. */ - static final class SortAfterFilter { + /** + * Apply {@link IntStream#filter(IntPredicate)} before {@link IntStream#sorted()} to reduce the + * number of elements to sort. + */ + static final class IntStreamFilterSorted { @BeforeTemplate IntStream before(IntStream stream, IntPredicate predicate) { return stream.sorted().filter(predicate); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java index a5eefa9181..76da55b072 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java @@ -154,8 +154,11 @@ LongStream after(Stream stream, LongFunction function) } } - /** Apply filtering before sorting to reduce the number of elements to sort. */ - static final class SortAfterFilter { + /** + * Apply {@link LongStream#filter(LongPredicate)} before {@link LongStream#sorted()} to reduce the + * number of elements to sort. + */ + static final class LongStreamFilterSorted { @BeforeTemplate LongStream before(LongStream stream, LongPredicate predicate) { return stream.sorted().filter(predicate); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index a47d1c75a8..5064b332d2 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1248,8 +1248,11 @@ Duration after(StepVerifier.LastStep step, Duration duration) { } } - /** Apply filtering before sorting to reduce the number of elements to sort. */ - static final class SortAfterFilter { + /** + * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort()} to reduce the number of + * elements to sort. + */ + static final class StreamFilterSorted { @BeforeTemplate Flux before(Flux flux, Predicate predicate) { return flux.sort().filter(predicate); @@ -1261,8 +1264,11 @@ Flux after(Flux flux, Predicate predicate) { } } - /** Apply filtering before sorting with a comparator to reduce the number of elements to sort. */ - static final class SortWithComparatorAfterFilter { + /** + * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort(Comparator)} to reduce the number + * of elements to sort. + */ + static final class StreamFilterSortedWithComparator { @BeforeTemplate Flux before(Flux flux, Predicate predicate, Comparator comparator) { return flux.sort(comparator).filter(predicate); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 68c4a53b21..251fdea9c6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -167,8 +167,11 @@ Stream after(Stream stream, Function { + /** + * Apply {@link Stream#filter(Predicate)} before {@link Stream#sorted()} to reduce the number of + * elements to sort. + */ + static final class StreamFilterSorted { @BeforeTemplate Stream before(Stream stream, Predicate predicate) { return stream.sorted().filter(predicate); @@ -180,8 +183,11 @@ Stream after(Stream stream, Predicate predicate) { } } - /** Apply filter before sorting with a comparator to reduce the number of elements to sort. */ - static final class SortWithComparatorAfterFilter { + /** + * Apply {@link Stream#filter(Predicate)} before {@link Stream#sorted(Comparator)} to reduce the + * number of elements to sort. + */ + static final class StreamFilterSortedWithComparator { @BeforeTemplate Stream before( Stream stream, Predicate predicate, Comparator comparator) { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java index da75410ab9..5f8ab5a000 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java @@ -46,7 +46,7 @@ DoubleStream testFlatMapOuterStreamAfterFlatMapToDouble() { return Stream.of(1).flatMapToDouble(v -> DoubleStream.of(v * v).flatMap(DoubleStream::of)); } - DoubleStream testSortAfterFilter() { + DoubleStream testDoubleStreamFilterSorted() { return DoubleStream.of(1, 4, 3, 2).sorted().filter(d -> d % 2 == 0); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java index 143096c684..c382f567c8 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java @@ -46,7 +46,7 @@ DoubleStream testFlatMapOuterStreamAfterFlatMapToDouble() { return Stream.of(1).flatMapToDouble(v -> DoubleStream.of(v * v)).flatMap(DoubleStream::of); } - DoubleStream testSortAfterFilter() { + DoubleStream testDoubleStreamFilterSorted() { return DoubleStream.of(1, 4, 3, 2).filter(d -> d % 2 == 0).sorted(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java index dcd2b23168..6ff668b016 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java @@ -50,7 +50,7 @@ IntStream testFlatMapOuterStreamAfterFlatMapToInt() { return Stream.of(1).flatMapToInt(v -> IntStream.of(v * v).flatMap(IntStream::of)); } - IntStream testSortAfterFilter() { + IntStream testIntStreamFilterSorted() { return IntStream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java index ceeb22adb9..23ab645e09 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java @@ -50,7 +50,7 @@ IntStream testFlatMapOuterStreamAfterFlatMapToInt() { return Stream.of(1).flatMapToInt(v -> IntStream.of(v * v)).flatMap(IntStream::of); } - IntStream testSortAfterFilter() { + IntStream testIntStreamFilterSorted() { return IntStream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java index a5727de9f9..83e4bb6a4a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java @@ -50,7 +50,7 @@ LongStream testFlatMapOuterStreamAfterFlatMapToLong() { return Stream.of(1).flatMapToLong(v -> LongStream.of(v * v).flatMap(LongStream::of)); } - LongStream testSortAfterFilter() { + LongStream testLongStreamFilterSorted() { return LongStream.of(1, 4, 3, 2).sorted().filter(l -> l % 2 == 0); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java index 198bb98b8e..629028e76a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java @@ -50,7 +50,7 @@ LongStream testFlatMapOuterStreamAfterFlatMapToLong() { return Stream.of(1).flatMapToLong(v -> LongStream.of(v * v)).flatMap(LongStream::of); } - LongStream testSortAfterFilter() { + LongStream testLongStreamFilterSorted() { return LongStream.of(1, 4, 3, 2).filter(l -> l % 2 == 0).sorted(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 00e2b5a736..c36b364fd7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -1,5 +1,6 @@ package tech.picnic.errorprone.refasterrules; +import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; @@ -7,7 +8,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; -import java.util.Comparator; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; @@ -387,13 +387,11 @@ Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).expectTimeout(Duration.ZERO).verify(); } - Flux testSortAfterFilter() { + Flux testStreamFilterSorted() { return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); } - Flux testSortWithComparatorAfterFilter() { - return Flux.just(1, 4, 3, 2) - .sort(Comparator.comparingInt(Integer::intValue).reversed()) - .filter(i -> i % 2 == 0); + Flux testStreamFilterSortedWithComparator() { + return Flux.just(1, 4, 3, 2).sort(reverseOrder()).filter(i -> i % 2 == 0); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 46a942a0c1..a2c38b07f7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.MoreCollectors.toOptional; +import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; import static reactor.function.TupleUtils.function; @@ -9,7 +10,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; -import java.util.Comparator; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; @@ -380,13 +380,11 @@ Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).verifyTimeout(Duration.ZERO); } - Flux testSortAfterFilter() { + Flux testStreamFilterSorted() { return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(); } - Flux testSortWithComparatorAfterFilter() { - return Flux.just(1, 4, 3, 2) - .filter(i -> i % 2 == 0) - .sort(Comparator.comparingInt(Integer::intValue).reversed()); + Flux testStreamFilterSortedWithComparator() { + return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(reverseOrder()); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index 4482d40470..3bb32a4e6a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -7,7 +7,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; -import java.util.Comparator; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -17,7 +16,7 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder()); + return ImmutableSet.of(Objects.class, Streams.class, not(null)); } String testJoining() { @@ -132,13 +131,11 @@ boolean testStreamAllMatch2() { return Stream.of("foo").noneMatch(s -> !s.isBlank()); } - Stream testSortAfterFilter() { + Stream testStreamFilterSorted() { return Stream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); } - Stream testSortWithComparatorAfterFilter() { - return Stream.of(1, 4, 3, 2) - .sorted(Comparator.comparingInt(Integer::intValue).reversed()) - .filter(i -> i % 2 == 0); + Stream testStreamFilterSortedWithComparator() { + return Stream.of(1, 4, 3, 2).sorted(reverseOrder()).filter(i -> i % 2 == 0); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index e91da0eb03..4868a216c8 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -9,7 +9,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import java.util.Arrays; -import java.util.Comparator; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -19,7 +18,7 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder()); + return ImmutableSet.of(Objects.class, Streams.class, not(null)); } String testJoining() { @@ -131,13 +130,11 @@ boolean testStreamAllMatch2() { return Stream.of("foo").allMatch(s -> s.isBlank()); } - Stream testSortAfterFilter() { + Stream testStreamFilterSorted() { return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); } - Stream testSortWithComparatorAfterFilter() { - return Stream.of(1, 4, 3, 2) - .filter(i -> i % 2 == 0) - .sorted(Comparator.comparingInt(Integer::intValue).reversed()); + Stream testStreamFilterSortedWithComparator() { + return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(reverseOrder()); } } From ecf45bcebaf76eb830820c5c53d6fc0a96df29ba Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 8 Dec 2022 08:25:11 +0100 Subject: [PATCH 4/5] Rename, move some stuff --- .../refasterrules/ReactorRules.java | 64 +++++++++---------- .../refasterrules/ReactorRulesTestInput.java | 16 ++--- .../refasterrules/ReactorRulesTestOutput.java | 16 ++--- .../refasterrules/StreamRulesTestInput.java | 16 ++--- .../refasterrules/StreamRulesTestOutput.java | 16 ++--- 5 files changed, 64 insertions(+), 64 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 5064b332d2..2d4989ab32 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1063,6 +1063,38 @@ Flux after(Flux flux, Class clazz, T fallbackValue) { } } + /** + * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort()} to reduce the number of + * elements to sort. + */ + static final class StreamFilterSort { + @BeforeTemplate + Flux before(Flux flux, Predicate predicate) { + return flux.sort().filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate) { + return flux.filter(predicate).sort(); + } + } + + /** + * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort(Comparator)} to reduce the number + * of elements to sort. + */ + static final class StreamFilterSortWithComparator { + @BeforeTemplate + Flux before(Flux flux, Predicate predicate, Comparator comparator) { + return flux.sort(comparator).filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate, Comparator comparator) { + return flux.filter(predicate).sort(comparator); + } + } + /** Prefer {@link reactor.util.context.Context#empty()}} over more verbose alternatives. */ // XXX: Consider introducing an `IsEmpty` matcher that identifies a wide range of guaranteed-empty // `Collection` and `Map` expressions. @@ -1247,36 +1279,4 @@ Duration after(StepVerifier.LastStep step, Duration duration) { return step.verifyTimeout(duration); } } - - /** - * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort()} to reduce the number of - * elements to sort. - */ - static final class StreamFilterSorted { - @BeforeTemplate - Flux before(Flux flux, Predicate predicate) { - return flux.sort().filter(predicate); - } - - @AfterTemplate - Flux after(Flux flux, Predicate predicate) { - return flux.filter(predicate).sort(); - } - } - - /** - * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort(Comparator)} to reduce the number - * of elements to sort. - */ - static final class StreamFilterSortedWithComparator { - @BeforeTemplate - Flux before(Flux flux, Predicate predicate, Comparator comparator) { - return flux.sort(comparator).filter(predicate); - } - - @AfterTemplate - Flux after(Flux flux, Predicate predicate, Comparator comparator) { - return flux.filter(predicate).sort(comparator); - } - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index c36b364fd7..075f78ec1f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -328,6 +328,14 @@ Flux testFluxOnErrorReturn() { return Flux.just(1).onErrorReturn(IllegalArgumentException.class::isInstance, 2); } + Flux testStreamFilterSort() { + return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); + } + + Flux testStreamFilterSortWithComparator() { + return Flux.just(1, 4, 3, 2).sort(reverseOrder()).filter(i -> i % 2 == 0); + } + ImmutableSet testContextEmpty() { return ImmutableSet.of(Context.of(new HashMap<>()), Context.of(ImmutableMap.of())); } @@ -386,12 +394,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).expectTimeout(Duration.ZERO).verify(); } - - Flux testStreamFilterSorted() { - return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); - } - - Flux testStreamFilterSortedWithComparator() { - return Flux.just(1, 4, 3, 2).sort(reverseOrder()).filter(i -> i % 2 == 0); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index a2c38b07f7..e7a6980aba 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -323,6 +323,14 @@ Flux testFluxOnErrorReturn() { return Flux.just(1).onErrorReturn(IllegalArgumentException.class, 2); } + Flux testStreamFilterSort() { + return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(); + } + + Flux testStreamFilterSortWithComparator() { + return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(reverseOrder()); + } + ImmutableSet testContextEmpty() { return ImmutableSet.of(Context.empty(), Context.empty()); } @@ -379,12 +387,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return StepVerifier.create(Mono.empty()).verifyTimeout(Duration.ZERO); } - - Flux testStreamFilterSorted() { - return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(); - } - - Flux testStreamFilterSortedWithComparator() { - return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(reverseOrder()); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index 3bb32a4e6a..0f291c343e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -56,6 +56,14 @@ Stream testFlatMapOuterStreamAfterFlatMap() { return Stream.of("foo").flatMap(v -> Stream.of(v.length()).flatMap(Stream::of)); } + Stream testStreamFilterSorted() { + return Stream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); + } + + Stream testStreamFilterSortedWithComparator() { + return Stream.of(1, 4, 3, 2).sorted(reverseOrder()).filter(i -> i % 2 == 0); + } + ImmutableSet> testStreamMapFirst() { return ImmutableSet.of( Stream.of("foo").map(s -> s.length()).findFirst(), @@ -130,12 +138,4 @@ ImmutableSet testStreamAllMatch() { boolean testStreamAllMatch2() { return Stream.of("foo").noneMatch(s -> !s.isBlank()); } - - Stream testStreamFilterSorted() { - return Stream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); - } - - Stream testStreamFilterSortedWithComparator() { - return Stream.of(1, 4, 3, 2).sorted(reverseOrder()).filter(i -> i % 2 == 0); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index 4868a216c8..19e7d9fdda 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -57,6 +57,14 @@ Stream testFlatMapOuterStreamAfterFlatMap() { return Stream.of("foo").flatMap(v -> Stream.of(v.length())).flatMap(Stream::of); } + Stream testStreamFilterSorted() { + return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); + } + + Stream testStreamFilterSortedWithComparator() { + return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(reverseOrder()); + } + ImmutableSet> testStreamMapFirst() { return ImmutableSet.of( Stream.of("foo").findFirst().map(s -> s.length()), @@ -129,12 +137,4 @@ ImmutableSet testStreamAllMatch() { boolean testStreamAllMatch2() { return Stream.of("foo").allMatch(s -> s.isBlank()); } - - Stream testStreamFilterSorted() { - return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); - } - - Stream testStreamFilterSortedWithComparator() { - return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(reverseOrder()); - } } From 11b55c6223fb77e5a93a4893e1362048ac16b221 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 8 Dec 2022 20:42:55 +0100 Subject: [PATCH 5/5] Suggestions --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 4 ++-- .../errorprone/refasterrules/ReactorRulesTestInput.java | 4 ++-- .../errorprone/refasterrules/ReactorRulesTestOutput.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 2d4989ab32..e698b07f59 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1067,7 +1067,7 @@ Flux after(Flux flux, Class clazz, T fallbackValue) { * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort()} to reduce the number of * elements to sort. */ - static final class StreamFilterSort { + static final class FluxFilterSort { @BeforeTemplate Flux before(Flux flux, Predicate predicate) { return flux.sort().filter(predicate); @@ -1083,7 +1083,7 @@ Flux after(Flux flux, Predicate predicate) { * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort(Comparator)} to reduce the number * of elements to sort. */ - static final class StreamFilterSortWithComparator { + static final class FluxFilterSortWithComparator { @BeforeTemplate Flux before(Flux flux, Predicate predicate, Comparator comparator) { return flux.sort(comparator).filter(predicate); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 075f78ec1f..6ee8cbf8fc 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -328,11 +328,11 @@ Flux testFluxOnErrorReturn() { return Flux.just(1).onErrorReturn(IllegalArgumentException.class::isInstance, 2); } - Flux testStreamFilterSort() { + Flux testFluxFilterSort() { return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); } - Flux testStreamFilterSortWithComparator() { + Flux testFluxFilterSortWithComparator() { return Flux.just(1, 4, 3, 2).sort(reverseOrder()).filter(i -> i % 2 == 0); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index e7a6980aba..5a15684ad4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -323,11 +323,11 @@ Flux testFluxOnErrorReturn() { return Flux.just(1).onErrorReturn(IllegalArgumentException.class, 2); } - Flux testStreamFilterSort() { + Flux testFluxFilterSort() { return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(); } - Flux testStreamFilterSortWithComparator() { + Flux testFluxFilterSortWithComparator() { return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(reverseOrder()); }