Skip to content

Commit

Permalink
So this is the alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Oct 7, 2023
1 parent 1a21e2a commit 4a451ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ ImmutableSet<Boolean> 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);
}

ImmutableSet<Boolean> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ ImmutableSet<Boolean> testBigDecimalSignumIsZero() {

ImmutableSet<Boolean> 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<Boolean> 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);
}
}

0 comments on commit 4a451ee

Please sign in to comment.