Skip to content

Commit

Permalink
CountingCLI: Replace if-else with switch statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjon3377 committed Nov 30, 2024
1 parent 4b0a9a7 commit 96ce4d1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions drivers.utility/src/main/java/utility/CountingCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,15 @@ private static Predicate<IFixture> notA(final Class<? extends IFixture> cls) {
return not(cls::isInstance);
}

@SuppressWarnings("ChainOfInstanceofChecks")
private static BigDecimal decimalize(final Number number) {
if (number instanceof Integer || number instanceof Long
|| number instanceof Short || number instanceof Byte) {
return BigDecimal.valueOf(number.longValue());
} else if (number instanceof final BigDecimal d) {
return d;
} else {
return BigDecimal.valueOf(number.doubleValue());
}
return switch (number) {
case final Integer _ -> BigDecimal.valueOf(number.longValue());
case final Long _ -> BigDecimal.valueOf(number.longValue());
case final Short _ -> BigDecimal.valueOf(number.longValue());
case final Byte _ -> BigDecimal.valueOf(number.longValue());
case final BigDecimal d -> d;
default -> BigDecimal.valueOf(number.doubleValue());
};
}

private static Stream<?> flatten(final Object item) {
Expand Down

0 comments on commit 96ce4d1

Please sign in to comment.