commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Barnhill <ericbarnh...@gmail.com>
Subject Re: [numbers] Redundant methods in ArithmeticUtils
Date Tue, 11 Jun 2019 17:26:36 GMT
On Tue, Jun 11, 2019 at 9:52 AM Heinrich Bohne <heinrich.bohne@gmx.at>
wrote:

> The class ArithmeticUtils in the commons-numbers-core module contains
> several methods where, since Java 8, equivalent methods in
> java.lang.Math exist. These methods are the following:
>
> addAndCheck(int, int)
> addAndCheck(long, long)
> mulAndCheck(int, int)
> mulAndCheck(long, long)
> subAndCheck(int, int)
> subAndCheck(long, long)
>
> The corresponding methods from java.lang.Math are:
>
> addExact(int, int)
> addExact(long, long)
> multiplyExact(int, int)
> multiplyExact(long, long)
> subtractExact(int, int)
> subtractExact(long, long)
>
> The former methods are probably relics from pre-Java-8 times, when the
> latter methods did not exist.


Often true with commons, and no shame in that.


> But now, they are redundant. I suggest
> they be removed from ArithmeticUtils in commons-numbers-core, and their
> invocations replaced by invocations of the java.lang.Math equivalents.
>

+1


> Both groups of methods specify the same type of exception to be thrown
> in case of an overflow (a java.lang.ArithmeticException), so the
> replacement should be straightforward.
>

Utils classes are of course frowned upon in general, so IMO the less in
there the better.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message