nnivruth commented on a change in pull request #495: LANG-1519 Add zero/positive/negative util methods URL: https://github.com/apache/commons-lang/pull/495#discussion_r382966556
########## File path: src/main/java/org/apache/commons/lang3/math/NumberUtils.java ########## @@ -1822,4 +1824,125 @@ public static int compare(final short x, final short y) { public static int compare(final byte x, final byte y) { return x - y; } + + /** + * <p>Checks if a {@code Number} value is zero, + * handling {@code null} by returning {@code false}.</p> + * + * @param number the {@code number} to check, {@code null} returns {@code false} + * @return {@code true} only if the input is non-null and equals zero + * @since 3.10 + */ + public static boolean isZero(final Number number) { + if (Objects.isNull(number)) { + return false; + } else if (number instanceof Integer) { + return number.intValue() == INTEGER_ZERO; + } else if (number instanceof Long) { + return number.longValue() == LONG_ZERO; + } else if (number instanceof Byte) { + return number.byteValue() == BYTE_ZERO; + } else if (number instanceof Short) { + return number.shortValue() == SHORT_ZERO; + } else if (number instanceof Float) { + return number.floatValue() == FLOAT_ZERO; + } else if (number instanceof Double) { + return number.doubleValue() == DOUBLE_ZERO; + } + + return false; Review comment: agree, updated the methods. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services