[ 
https://issues.apache.org/jira/browse/LANG-1519?focusedWorklogId=391267&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-391267
 ]

ASF GitHub Bot logged work on LANG-1519:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 23/Feb/20 01:19
            Start Date: 23/Feb/20 01:19
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on pull request #495: LANG-1519 
Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#discussion_r382954510
 
 

 ##########
 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:
   This is wrong IMO, if I create a subclass of `Number`, this method will 
always return false even if my `Number`'s intValue() returns 0. 
 
----------------------------------------------------------------
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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 391267)
    Time Spent: 2h  (was: 1h 50m)

> Add Integer Utils to library
> ----------------------------
>
>                 Key: LANG-1519
>                 URL: https://issues.apache.org/jira/browse/LANG-1519
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Nivruth Nandigam
>            Priority: Trivial
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> Create Integer Utils class for useful integer operations and a placeholder 
> for adding more useful/important utility functions
>  
> Pull Request: [https://github.com/apache/commons-lang/pull/495]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to