StatUtils { public static double[] mode(double[] sample) throws MathIllegalArgumentException { if (sample == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return getMode(sample, 0, sample.length); } private  StatUtils(); static double sum(final double[] values); static double sum(final double[] values, final int begin,
            final int length); static double sumSq(final double[] values); static double sumSq(final double[] values, final int begin,
            final int length); static double product(final double[] values); static double product(final double[] values, final int begin,
            final int length); static double sumLog(final double[] values); static double sumLog(final double[] values, final int begin,
            final int length); static double mean(final double[] values); static double mean(final double[] values, final int begin,
            final int length); static double geometricMean(final double[] values); static double geometricMean(final double[] values, final int begin,
            final int length); static double variance(final double[] values); static double variance(final double[] values, final int begin,
            final int length); static double variance(final double[] values, final double mean,
            final int begin, final int length); static double variance(final double[] values, final double mean); static double populationVariance(final double[] values); static double populationVariance(final double[] values, final int begin,
            final int length); static double populationVariance(final double[] values, final double mean,
            final int begin, final int length); static double populationVariance(final double[] values, final double mean); static double max(final double[] values); static double max(final double[] values, final int begin,
            final int length); static double min(final double[] values); static double min(final double[] values, final int begin,
            final int length); static double percentile(final double[] values, final double p); static double percentile(final double[] values, final int begin,
            final int length, final double p); static double sumDifference(final double[] sample1, final double[] sample2); static double meanDifference(final double[] sample1, final double[] sample2); static double varianceDifference(final double[] sample1,
            final double[] sample2, double meanDifference); static double[] normalize(final double[] sample); static double[] mode(double[] sample); static double[] mode(double[] sample, final int begin, final int length);  }
@Test public void testMode() { final double[] singleMode = {0, 1, 0, 2, 7, 11, 12}; final double[] modeSingle = StatUtils.mode(singleMode); Assert.assertEquals(0, modeSingle[0], Double.MIN_VALUE); Assert.assertEquals(1, modeSingle.length); final double[] twoMode = {0, 1, 2, 0, 2, 3, 7, 11}; final double[] modeDouble = StatUtils.mode(twoMode); Assert.assertEquals(0, modeDouble[0], Double.MIN_VALUE); Assert.assertEquals(2, modeDouble[1], Double.MIN_VALUE); Assert.assertEquals(2, modeDouble.length); final double[] nanInfested = {0, 0, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN, 2, 2, 2, 3, 5}; final double[] modeNan = StatUtils.mode(nanInfested); Assert.assertEquals(0, modeNan[0], Double.MIN_VALUE); Assert.assertEquals(2, modeNan[1], Double.MIN_VALUE); Assert.assertEquals(2, modeNan.length); final double[] infInfested = {0, 0, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 2, 2, 3, 5}; final double[] modeInf = StatUtils.mode(infInfested); Assert.assertEquals(Double.NEGATIVE_INFINITY, modeInf[0], Double.MIN_VALUE); Assert.assertEquals(0, modeInf[1], Double.MIN_VALUE); Assert.assertEquals(2, modeInf[2], Double.MIN_VALUE); Assert.assertEquals(Double.POSITIVE_INFINITY, modeInf[3], Double.MIN_VALUE); Assert.assertEquals(4, modeInf.length); final double[] noData = {}; final double[] modeNodata = StatUtils.mode(noData); Assert.assertEquals(0, modeNodata.length); final double[] nansOnly = {Double.NaN, Double.NaN}; final double[] modeNansOnly = StatUtils.mode(nansOnly); Assert.assertEquals(0, modeNansOnly.length); final double[] nullArray = null; try { StatUtils.mode(nullArray); Assert.fail("Expecting MathIllegalArgumentException"); } catch (MathIllegalArgumentException ex) { } }