Skip to content

Commit

Permalink
Refactor ShowTableStatusMergedResult (#32803)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Sep 7, 2024
1 parent 3bb0f6c commit 28b10eb
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,18 @@ private void merge(final MemoryQueryResultRow row, final MemoryQueryResultRow ne
}

private BigInteger sum(final Object num1, final Object num2) {
if (num1 == null && num2 == null) {
return null;
}
return getNonNullBigInteger(num1).add(getNonNullBigInteger(num2));
return null == num1 && null == num2 ? null : getNonNullBigInteger(num1).add(getNonNullBigInteger(num2));
}

private BigInteger avg(final Object sum, final Object number) {
if (sum == null && number == null) {
if (null == sum && null == number) {
return null;
}
BigInteger numberBigInteger = getNonNullBigInteger(number);
return BigInteger.ZERO.equals(numberBigInteger) ? BigInteger.ZERO : getNonNullBigInteger(sum).divide(numberBigInteger);
}

private BigInteger getNonNullBigInteger(final Object value) {
return Optional.ofNullable(value)
.filter(BigInteger.class::isInstance)
.map(BigInteger.class::cast)
.orElse(BigInteger.ZERO);
return Optional.ofNullable(value).filter(BigInteger.class::isInstance).map(BigInteger.class::cast).orElse(BigInteger.ZERO);
}
}

0 comments on commit 28b10eb

Please sign in to comment.