You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/02/21 02:35:39 UTC

[GitHub] [commons-lang] nnivruth opened a new pull request #495: LANG-1519 Add Integer Utils to library

nnivruth opened a new pull request #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495
 
 
   Create Integer Utils class for useful integer operations and a placeholder for adding more useful/important utility functions

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/28962642/badge)](https://coveralls.io/builds/28962642)
   
   Coverage increased (+0.02%) to 95.118% when pulling **938531a9f7a6e2a753e9b01d574d0095a77be6cb on nnivruth:master** into **94b3784fdec5d0e9d63e4aec6772144b68283790 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] ameyjadiye commented on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
ameyjadiye commented on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589567930
 
 
   Shouldn't this be the part of Math-related projects? like common numbers?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-601337561
 
 
   > Hi @nnivruth
   > In general, since we are a general purpose library, I would say that you should consider all subclasses of `Number` that are built-in the Java 8 JRE with maybe a bias to considering only what is in Java 11's `java.base` module in order to make it easier on us going forward though I would imagine that our requiring Java 11 as a base requirement is a long ways off (just a guess on that one.)
   
   Thanks @garydgregory ! I've also added Long Accumulator, Long Adder, Double Accumulator, Double Adder which covers [known Number subclasses](https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html). 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-593574286
 
 
   What about other JRE numbers like atomic numbers and big numbers? How should those be treated?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/29462551/badge)](https://coveralls.io/builds/29462551)
   
   Coverage increased (+0.02%) to 95.12% when pulling **c9f50f23a8015aae44f17c041c9ae6779aa4db91 on nnivruth:master** into **6240c11f225e68bab717ee0c188e10ac479ba035 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on a change in pull request #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in 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 bogus 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/29462515/badge)](https://coveralls.io/builds/29462515)
   
   Coverage increased (+0.02%) to 95.12% when pulling **c9f50f23a8015aae44f17c041c9ae6779aa4db91 on nnivruth:master** into **6240c11f225e68bab717ee0c188e10ac479ba035 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/29462551/badge)](https://coveralls.io/builds/29462551)
   
   Coverage increased (+0.02%) to 95.12% when pulling **c9f50f23a8015aae44f17c041c9ae6779aa4db91 on nnivruth:master** into **6240c11f225e68bab717ee0c188e10ac479ba035 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on a change in pull request #495: LANG-1519 Add zero/positive/negative util methods

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-591078721
 
 
   What should these method return when a double is not-a-number?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on a change in pull request #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589471163
 
 
   https://issues.apache.org/jira/browse/LANG-1519

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
garydgregory commented on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589652896
 
 
   -1 in Commons Lang, we had a `NumberUtil`s class in 2.x but it was deprecated and removed in 3.0. That code now lives in Apache Commons Math IIRC. Also, it does not make sense as typed to `Integer` when you can type to its `Number` superclass.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on a change in pull request #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
nnivruth commented on a change in pull request #495: LANG-1519 Add Integer Utils to library
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 func.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-600986710
 
 
   > What about other JRE numbers like atomic numbers and big numbers? How should those be treated?
   
   @garydgregory one way to handle special numbers (BigInteger, BigDecimal, AtomicInteger, AtomicLong) is to add them as special instance checks (additional else-if blocks in each method) but not sure if that's the best way. do you have any suggestions/feedback?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-601159310
 
 
   Hi @nnivruth 
   In general, since we are a general purpose library, I would say that you should consider all subclasses of `Number` that are built-in the Java 8 JRE with maybe a bias to considering only what is in Java 11's `java.base` module in order to make it easier on us going forward though I would imagine that our requiring Java 11 as a base requirement is a long ways off (just a guess on that one.)
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on a change in pull request #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
nnivruth commented on a change in pull request #495: LANG-1519 Add Integer Utils to library
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 method.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/29480227/badge)](https://coveralls.io/builds/29480227)
   
   Coverage increased (+0.02%) to 95.109% when pulling **1f498beda2a0384c255e134d548163dcdf7a0061 on nnivruth:master** into **1c42dfb05791a1172e03d355d296327c013177f9 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-591187253
 
 
   > What should these method return when a double is not-a-number?
   
   @garydgregory, great question. IMO the methods isZero(), isPositive(), isNegative() should return false for float/double NaNs & vice versa for isNotZero(), isNotPositive(), isNotNegative(). I've added these to the test cases as well. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
garydgregory commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-602246497
 
 
   @nnivruth ,
   Thank you for your updates. The code covers all the cases it seems which is nice. The drawback ATM is that it does not feel very OO. I am wondering if all of this could be implemented in terms of a new utility method called compare(Number, Number) which would allow the isZero, isPositive and isNegative to be implemented by calling compare(aNumber, ZERO). More thinking and experimenting needed...
   
   This is all non-trivial, so I think I might cut a 3.10 RC which I am late on and this PR would end up in 3.11.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-590008121
 
 
   @ameyjadiye @garydgregory refactored & moved to NumberUtils

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-600960419
 
 
   @garydgregory one way to handle special numbers (BigInteger, BigDecimal, AtomicInteger, AtomicLong) is to add them as special instance checks (additional else-if blocks in each method) but not sure if that's the best way. do you have any suggestions/feedback? 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on a change in pull request #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in 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 bogus IMO, if I create a subclass of `Number`, this method will always return false even if my `Number`'s intValue() returns 0. Why is this whole method's implementation not simply `return number.doubleValue() == DOUBLE_ZERO` ?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls commented on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
coveralls commented on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/28870045/badge)](https://coveralls.io/builds/28870045)
   
   Coverage decreased (-0.004%) to 95.098% when pulling **6067c420589951a32e98562b876b6b8e881bb696 on nnivruth:master** into **eb8d069089364e396e37ed5273cf7710e41eb06d on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth removed a comment on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth removed a comment on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-600960419
 
 
   @garydgregory one way to handle special numbers (BigInteger, BigDecimal, AtomicInteger, AtomicLong) is to add them as special instance checks (additional else-if blocks in each method) but not sure if that's the best way. do you have any suggestions/feedback? 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-615014953
 
 
   @garydgregory ,
   Been thinking and trying to make these functions more OO and rely on a single method but seeing some difficulties with type casting (esp for special types of number implementations - BigDecimal, etc), NaNs and custom Number implementations. 
   
   Some examples:
   
   - the isZero() function with the current impl does a direct equality check and returns true when passed with (-0.0d). IMO this is acceptable and correct but with the new impl it'll return false
   
   - the functions isZero(), isPositive(), isNegative() return false for float/double NaNs & vice versa for isNotZero(), isNotPositive(), isNotNegative() but with compare we might have to add special checks for these scenarios
   
   
   your thoughts/inputs on how to proceed?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] garydgregory commented on a change in pull request #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in 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 bogus IMO, if I create a subclass of `Number`, this method will always return false even if my `Number`'s inValue() returns 0. Why is this whole method's implementation not simply `return number.doubleValue() == DOUBLE_ZERO` ?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/28900868/badge)](https://coveralls.io/builds/28900868)
   
   Coverage increased (+0.004%) to 95.105% when pulling **78b691fdded3027f9be7b42de3d3430f5f59d778 on nnivruth:master** into **94b3784fdec5d0e9d63e4aec6772144b68283790 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/28899542/badge)](https://coveralls.io/builds/28899542)
   
   Coverage increased (+0.008%) to 95.11% when pulling **2210d8bd901759a6a8187b349cec209804bfef1f on nnivruth:master** into **eb8d069089364e396e37ed5273cf7710e41eb06d on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] coveralls edited a comment on issue #495: LANG-1519 Add Integer Utils to library

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #495: LANG-1519 Add Integer Utils to library
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-589476556
 
 
   
   [![Coverage Status](https://coveralls.io/builds/28899579/badge)](https://coveralls.io/builds/28899579)
   
   Coverage increased (+0.02%) to 95.116% when pulling **59c5ffe0f542d776a4b554067add64e5086bf9d6 on nnivruth:master** into **94b3784fdec5d0e9d63e4aec6772144b68283790 on apache:master**.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-lang] nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods

Posted by GitBox <gi...@apache.org>.
nnivruth commented on issue #495: LANG-1519 Add zero, positive & negative util methods
URL: https://github.com/apache/commons-lang/pull/495#issuecomment-601337561
 
 
   > Hi @nnivruth
   > In general, since we are a general purpose library, I would say that you should consider all subclasses of `Number` that are built-in the Java 8 JRE with maybe a bias to considering only what is in Java 11's `java.base` module in order to make it easier on us going forward though I would imagine that our requiring Java 11 as a base requirement is a long ways off (just a guess on that one.)
   
   Thanks @garydgregory ! I've also added Long Accumulator, Long Adder, Double Accumulator, Double Adder which covers [known Number classes](https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html). 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services