WinsorizedMeanCalculator extends Function1D<double[], Double> { @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); final int length = x.length; Validate.isTrue(length > 0, "x was empty"); final double[] winsorized = Arrays.copyOf(x, length); Arrays.sort(winsorized); final int value = (int) Math.round(length * _gamma); final double x1 = winsorized[value]; final double x2 = winsorized[length - value - 1]; for (int i = 0; i < value; i++) { winsorized[i] = x1; winsorized[length - 1 - i] = x2; } return MEAN_CALCULATOR.evaluate(winsorized); } WinsorizedMeanCalculator(final double gamma); @Override Double evaluate(final double[] x);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullArray() { CALCULATOR.evaluate((double[]) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyArray() { CALCULATOR.evaluate(new double[0]); }
@Test public void test() { final double[] x = new double[N]; for (int i = 0; i < 10; i++) { x[i] = Double.valueOf(10); } for (int i = 10; i < N - 10; i++) { x[i] = Double.valueOf(i); } for (int i = N - 10; i < N; i++) { x[i] = Double.valueOf(N - 10 - 1); } assertEquals(CALCULATOR.evaluate(x), MEAN.evaluate(x), EPS); for (int i = 0; i < N - 1; i++) { x[i] = Double.valueOf(i); } x[N - 1] = 100000.; assertTrue(CALCULATOR.evaluate(x) < MEAN.evaluate(x)); }