Re: [Math] MATH-1408 (exceptions for control flow)
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 . This class provides a frequency table for users (implemented with a TreeMap) and methods to retrieve the mode, unique count, count, sum of frequencies, etc.
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 values.
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?