From 4a451ee56e467de86b60fe0f317389c0dc7708f7 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 7 Oct 2023 14:44:32 +0200 Subject: [PATCH] So this is the alternative --- .../refasterrules/BigDecimalRules.java | 12 +++---- .../BigDecimalRulesTestInput.java | 8 ++--- .../BigDecimalRulesTestOutput.java | 32 +++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java index e70c342c662..3800828a805 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java @@ -84,7 +84,7 @@ boolean after(BigDecimal value) { } /** - * Prefer a {@link BigDecimal#signum()} comparison to 0 over more contrived or less clear + * Prefer a {@link BigDecimal#signum()} comparison to 1 over more contrived or less clear * alternatives. */ static final class BigDecimalSignumIsPositive { @@ -93,19 +93,19 @@ boolean before(BigDecimal value) { return Refaster.anyOf( value.compareTo(BigDecimal.ZERO) > 0, BigDecimal.ZERO.compareTo(value) < 0, - value.signum() == 1, + value.signum() > 0, value.signum() >= 1); } @AfterTemplate @AlsoNegation boolean after(BigDecimal value) { - return value.signum() > 0; + return value.signum() == 1; } } /** - * Prefer a {@link BigDecimal#signum()} comparison to 0 over more contrived or less clear + * Prefer a {@link BigDecimal#signum()} comparison to -1 over more contrived or less clear * alternatives. */ static final class BigDecimalSignumIsNegative { @@ -114,14 +114,14 @@ boolean before(BigDecimal value) { return Refaster.anyOf( value.compareTo(BigDecimal.ZERO) < 0, BigDecimal.ZERO.compareTo(value) > 0, - value.signum() == -1, + value.signum() < 0, value.signum() <= -1); } @AfterTemplate @AlsoNegation boolean after(BigDecimal value) { - return value.signum() < 0; + return value.signum() == -1; } } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java index 1fb1f49b3cc..79dcc5ae54d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java @@ -33,11 +33,11 @@ ImmutableSet testBigDecimalSignumIsPositive() { return ImmutableSet.of( BigDecimal.valueOf(1).compareTo(BigDecimal.ZERO) > 0, BigDecimal.ZERO.compareTo(BigDecimal.valueOf(2)) < 0, - BigDecimal.valueOf(3).signum() == 1, + BigDecimal.valueOf(3).signum() > 0, BigDecimal.valueOf(4).signum() >= 1, BigDecimal.valueOf(5).compareTo(BigDecimal.ZERO) <= 0, BigDecimal.ZERO.compareTo(BigDecimal.valueOf(6)) >= 0, - BigDecimal.valueOf(7).signum() != 1, + BigDecimal.valueOf(7).signum() <= 0, BigDecimal.valueOf(8).signum() < 1); } @@ -45,11 +45,11 @@ ImmutableSet testBigDecimalSignumIsNegative() { return ImmutableSet.of( BigDecimal.valueOf(1).compareTo(BigDecimal.ZERO) < 0, BigDecimal.ZERO.compareTo(BigDecimal.valueOf(2)) > 0, - BigDecimal.valueOf(3).signum() == -1, + BigDecimal.valueOf(3).signum() < 0, BigDecimal.valueOf(4).signum() <= -1, BigDecimal.valueOf(5).compareTo(BigDecimal.ZERO) >= 0, BigDecimal.ZERO.compareTo(BigDecimal.valueOf(6)) <= 0, - BigDecimal.valueOf(7).signum() != -1, + BigDecimal.valueOf(7).signum() >= 0, BigDecimal.valueOf(8).signum() > -1); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java index 5801fbc592e..ea73698f763 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java @@ -31,25 +31,25 @@ ImmutableSet testBigDecimalSignumIsZero() { ImmutableSet testBigDecimalSignumIsPositive() { return ImmutableSet.of( - BigDecimal.valueOf(1).signum() > 0, - BigDecimal.valueOf(2).signum() > 0, - BigDecimal.valueOf(3).signum() > 0, - BigDecimal.valueOf(4).signum() > 0, - BigDecimal.valueOf(5).signum() <= 0, - BigDecimal.valueOf(6).signum() <= 0, - BigDecimal.valueOf(7).signum() <= 0, - BigDecimal.valueOf(8).signum() <= 0); + BigDecimal.valueOf(1).signum() == 1, + BigDecimal.valueOf(2).signum() == 1, + BigDecimal.valueOf(3).signum() == 1, + BigDecimal.valueOf(4).signum() == 1, + BigDecimal.valueOf(5).signum() != 1, + BigDecimal.valueOf(6).signum() != 1, + BigDecimal.valueOf(7).signum() != 1, + BigDecimal.valueOf(8).signum() != 1); } ImmutableSet testBigDecimalSignumIsNegative() { return ImmutableSet.of( - BigDecimal.valueOf(1).signum() < 0, - BigDecimal.valueOf(2).signum() < 0, - BigDecimal.valueOf(3).signum() < 0, - BigDecimal.valueOf(4).signum() < 0, - BigDecimal.valueOf(5).signum() >= 0, - BigDecimal.valueOf(6).signum() >= 0, - BigDecimal.valueOf(7).signum() >= 0, - BigDecimal.valueOf(8).signum() >= 0); + BigDecimal.valueOf(1).signum() == -1, + BigDecimal.valueOf(2).signum() == -1, + BigDecimal.valueOf(3).signum() == -1, + BigDecimal.valueOf(4).signum() == -1, + BigDecimal.valueOf(5).signum() != -1, + BigDecimal.valueOf(6).signum() != -1, + BigDecimal.valueOf(7).signum() != -1, + BigDecimal.valueOf(8).signum() != -1); } }