DoubleQuadraticInterpolator1D extends Interpolator1D { @Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { ArgumentChecker.notNull(value, "value"); ArgumentChecker.notNull(data, "data bundle"); ArgumentChecker.isTrue(data instanceof Interpolator1DDoubleQuadraticDataBundle, "data bundle is of wrong type"); final Interpolator1DDoubleQuadraticDataBundle quadraticData = (Interpolator1DDoubleQuadraticDataBundle) data; final int low = data.getLowerBoundIndex(value); final int high = low + 1; final int n = data.size() - 1; final double[] xData = data.getKeys(); final double[] yData = data.getValues(); if (low == n) { return yData[n]; } else if (low == 0) { final RealPolynomialFunction1D quadratic = quadraticData.getQuadratic(0); final double x = value - xData[1]; return quadratic.evaluate(x); } else if (high == n) { final RealPolynomialFunction1D quadratic = quadraticData.getQuadratic(n - 2); final double x = value - xData[n - 1]; return quadratic.evaluate(x); } final RealPolynomialFunction1D quadratic1 = quadraticData.getQuadratic(low - 1); final RealPolynomialFunction1D quadratic2 = quadraticData.getQuadratic(high - 1); final double w = _weightFunction.getWeight((xData[high] - value) / (xData[high] - xData[low])); final double res = w * quadratic1.evaluate(value - xData[low]) + (1 - w) * quadratic2.evaluate(value - xData[high]); return res; } DoubleQuadraticInterpolator1D();  DoubleQuadraticInterpolator1D(final WeightingFunction weightFunction); @Override Double interpolate(final Interpolator1DDataBundle data, final Double value); @Override double firstDerivative(final Interpolator1DDataBundle data, final Double value); @Override double[] getNodeSensitivitiesForValue(final Interpolator1DDataBundle data, final Double value); @Override Interpolator1DDoubleQuadraticDataBundle getDataBundle(final double[] x, final double[] y); @Override Interpolator1DDoubleQuadraticDataBundle getDataBundleFromSortedArrays(final double[] x, final double[] y);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { INTERPOLATOR.interpolate(null, 2.3); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullValue() { INTERPOLATOR.interpolate(DATA, null); }
@Test public void test() { for (int i = 0; i < X_TEST.length; i++) { assertEquals(INTERPOLATOR.interpolate(DATA, X_TEST[i]), Y_TEST[i], 1e-8); } }