Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Oct 6, 2023
1 parent b976b25 commit 368a107
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.errorprone.refaster.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.AlsoNegation;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import java.math.BigDecimal;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
Expand Down Expand Up @@ -76,31 +77,22 @@ boolean before(BigDecimal value) {
}

@AfterTemplate
@AlsoNegation
boolean after(BigDecimal value) {
return value.signum() == 0;
}
}

/** Prefer using {@link BigDecimal#signum()} over comparing to {@link BigDecimal#ZERO}. */
static final class BigDecimalCompareToNonZero {
@BeforeTemplate
boolean before(BigDecimal value) {
return Refaster.anyOf(
value.compareTo(BigDecimal.ZERO) != 0, BigDecimal.ZERO.compareTo(value) != 0);
}

@AfterTemplate
boolean after(BigDecimal value) {
return value.signum() != 0;
}
}

/** Prefer using {@link BigDecimal#signum()} over comparing to {@link BigDecimal#ZERO}. */
/** Prefer using {@link BigDecimal#signum()} over more contrived alternatives. */
static final class BigDecimalCompareToZeroPositive {
@BeforeTemplate
boolean before(BigDecimal value) {
return Refaster.anyOf(
value.compareTo(BigDecimal.ZERO) > 0, BigDecimal.ZERO.compareTo(value) < 0);
value.compareTo(BigDecimal.ZERO) > 0,
BigDecimal.ZERO.compareTo(value) < 0,
value.signum() > 0,
value.signum() >= 1,
value.signum() != -1);
}

@AfterTemplate
Expand Down Expand Up @@ -151,19 +143,6 @@ boolean after(BigDecimal value) {
}
}

/** {@link BigDecimal#signum()} does not produce values higher than {@code 1}. */
static final class BigDecimalPositiveSignum {
@BeforeTemplate
boolean before(BigDecimal value) {
return Refaster.anyOf(value.signum() > 0, value.signum() >= 1, value.signum() != -1);
}

@AfterTemplate
boolean after(BigDecimal value) {
return value.signum() == 1;
}
}

/** {@link BigDecimal#signum()} does not produce values lower than {@code -1}. */
static final class BigDecimalNegativeSignum {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ ImmutableSet<BigDecimal> testBigDecimalValueOf() {
ImmutableSet<Boolean> testBigDecimalCompareToZero() {
return ImmutableSet.of(
BigDecimal.ONE.compareTo(BigDecimal.ZERO) == 0,
BigDecimal.ZERO.compareTo(BigDecimal.ONE) == 0);
}

ImmutableSet<Boolean> testBigDecimalCompareToNonZero() {
return ImmutableSet.of(
BigDecimal.ZERO.compareTo(BigDecimal.ONE) == 0,
BigDecimal.ONE.compareTo(BigDecimal.ZERO) != 0,
BigDecimal.ZERO.compareTo(BigDecimal.ONE) != 0);
}

ImmutableSet<Boolean> testBigDecimalCompareToZeroPositive() {
return ImmutableSet.of(
BigDecimal.ONE.compareTo(BigDecimal.ZERO) > 0,
BigDecimal.ZERO.compareTo(BigDecimal.ONE) < 0);
BigDecimal.ZERO.compareTo(BigDecimal.ONE) < 0,
BigDecimal.ZERO.signum() > 0,
BigDecimal.ZERO.signum() >= 1,
BigDecimal.ZERO.signum() != -1);
}

ImmutableSet<Boolean> testBigDecimalCompareToZeroPositiveInclusive() {
Expand All @@ -57,13 +56,6 @@ ImmutableSet<Boolean> testBigDecimalCompareToZeroNegativeInclusive() {
BigDecimal.ZERO.compareTo(BigDecimal.ONE) >= 0);
}

ImmutableSet<Boolean> testBigDecimalPositiveSignum() {
return ImmutableSet.of(
BigDecimal.ZERO.signum() > 0,
BigDecimal.ZERO.signum() >= 1,
BigDecimal.ZERO.signum() != -1);
}

ImmutableSet<Boolean> testBigDecimalNegativeSignum() {
return ImmutableSet.of(
BigDecimal.ZERO.signum() < 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ ImmutableSet<BigDecimal> testBigDecimalValueOf() {
}

ImmutableSet<Boolean> testBigDecimalCompareToZero() {
return ImmutableSet.of(BigDecimal.ONE.signum() == 0, BigDecimal.ONE.signum() == 0);
}

ImmutableSet<Boolean> testBigDecimalCompareToNonZero() {
return ImmutableSet.of(BigDecimal.ONE.signum() != 0, BigDecimal.ONE.signum() != 0);
return ImmutableSet.of(
BigDecimal.ONE.signum() == 0,
BigDecimal.ONE.signum() == 0,
BigDecimal.ONE.signum() != 0,
BigDecimal.ONE.signum() != 0);
}

ImmutableSet<Boolean> testBigDecimalCompareToZeroPositive() {
return ImmutableSet.of(BigDecimal.ONE.signum() == 1, BigDecimal.ONE.signum() == 1);
return ImmutableSet.of(
BigDecimal.ONE.signum() == 1,
BigDecimal.ONE.signum() == 1,
BigDecimal.ZERO.signum() == 1,
BigDecimal.ZERO.signum() == 1,
BigDecimal.ZERO.signum() == 1);
}

ImmutableSet<Boolean> testBigDecimalCompareToZeroPositiveInclusive() {
Expand All @@ -45,13 +50,6 @@ ImmutableSet<Boolean> testBigDecimalCompareToZeroNegativeInclusive() {
return ImmutableSet.of(BigDecimal.ONE.signum() <= 0, BigDecimal.ONE.signum() <= 0);
}

ImmutableSet<Boolean> testBigDecimalPositiveSignum() {
return ImmutableSet.of(
BigDecimal.ZERO.signum() == 1,
BigDecimal.ZERO.signum() == 1,
BigDecimal.ZERO.signum() == 1);
}

ImmutableSet<Boolean> testBigDecimalNegativeSignum() {
return ImmutableSet.of(
BigDecimal.ZERO.signum() == -1,
Expand Down

0 comments on commit 368a107

Please sign in to comment.