commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita" <>
Subject Re: [Math] MATH-1408 (exceptions for control flow)
Date Fri, 07 Apr 2017 21:58:28 GMT
TL;DR we are working to replace ClassCastException (CCE) by either an instanceof check, or
a different approach. Right now, adding generics to Frequency would fix it, and (I think)
be a better design for the class

In Eclipse, I looked for the occurrences of CCE in [math], and the first place I picked to
work on was the Frequency class [1]. This class provides a frequency table for users (implemented
with a TreeMap) and methods to retrieve the mode, unique count, count, sum of frequencies,

The problem is that the Frequency class has an internal TreeMap, and offers users the ability
to store chars, ints, or longs, offering different methods to add values, get cumulative frequencies,
etc, for int / long / char.

Because of this design, the SortedMap is created with <Comparable<?>, Long>. The
keys, accepting any Comparable<?> (there is addValue(Comparable<?>) method), have
to check for CCE to make sure the user passed a key of a type that can be compared with the
other keys in the TreeMap. And it does even a workaround for invalid values, returning zero,
or ignoring errors. The map values also get boxed to Long's, as this supports all int/char

I think we can add generics to the Frequency class, as in this fork:

By doing that, we would break binary compatibility (it would be fine to wait for a major release
to ship it) but we would avoid runtime errors, remove warning suppression annotations, and
also remove the need to throw the MathIllegalArgumentException exception when adding values
and for other methods too.

Does anyone have any objections to generifying the Frequency class, or would have a use case
for a int/long/char Frequency class?



From: Gilles <>
To: Commons Developers List <> 
Sent: Saturday, 8 April 2017 1:54 AM
Subject: [Math] MATH-1408 (exceptions for control flow)



Any objection to the proposed changes?




To unsubscribe, e-mail:

For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message