From 5ee07033372dae847f87be4073d88efc56c67b20 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Mon, 20 Feb 2023 09:09:24 +0100 Subject: [PATCH] Introduce `MonoSingleOptional` Refaster rule --- .../errorprone/refasterrules/ReactorRules.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 c99c77482a5..85b0e69ce7f 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 @@ -717,6 +717,19 @@ Mono> after(Mono mono) { } } + /** Prefer {@link Mono#singleOptional()} over more contrived alternatives. */ + static final class MonoSingleOptional { + @BeforeTemplate + Mono> before(Mono mono) { + return mono.flux().collect(toOptional()); + } + + @AfterTemplate + Mono> after(Mono mono) { + return mono.singleOptional(); + } + } + /** Prefer {@link Mono#cast(Class)} over {@link Mono#map(Function)} with a cast. */ static final class MonoCast { @BeforeTemplate