PolynomialInterpolator1D extends Interpolator1D { @Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(value, "value"); Validate.notNull(data, "data bundle"); final int n = data.size(); final double[] keys = data.getKeys(); final double[] values = data.getValues(); if (n <= _degree) { throw new MathException("Need at least " + (_degree + 1) + " data points to perform polynomial interpolation of degree " + _degree); } if (data.getLowerBoundIndex(value) == n - 1) { return values[n - 1]; } final int lower = data.getLowerBoundIndex(value); final int lowerBound = lower - _offset; final int upperBound = _degree + 1 + lowerBound; if (lowerBound < 0) { throw new MathException("Could not get lower bound: index " + lowerBound + " must be greater than or equal to zero"); } if (upperBound > n + 1) { throw new MathException("Could not get upper bound: index " + upperBound + " must be less than or equal to " + (n + 1)); } final double[] x = Arrays.copyOfRange(keys, lowerBound, upperBound); final double[] y = Arrays.copyOfRange(values, lowerBound, upperBound); try { final PolynomialFunctionLagrangeForm lagrange = _interpolator.interpolate(x, y); return CommonsMathWrapper.unwrap(lagrange).evaluate(value); } catch (final org.apache.commons.math.MathException e) { throw new MathException(e); } } PolynomialInterpolator1D(final int degree);  PolynomialInterpolator1D(final int degree, final int offset); @Override Double interpolate(final Interpolator1DDataBundle data, final Double value); @Override Interpolator1DDataBundle getDataBundle(final double[] x, final double[] y); @Override Interpolator1DDataBundle getDataBundleFromSortedArrays(final double[] x, final double[] y); @Override boolean equals(final Object obj); @Override int hashCode(); @Override double[] getNodeSensitivitiesForValue(Interpolator1DDataBundle data, Double value);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDataBundle() { INTERPOLATOR_WITH_OFFSET.interpolate(null, 3.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { INTERPOLATOR_WITH_OFFSET.interpolate(MODEL, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testOutOfRange() { INTERPOLATOR_NO_OFFSET.interpolate(MODEL, 0.); }
@Test(expectedExceptions = MathException.class) public void testOutOfRangeWithOffset() { INTERPOLATOR_WITH_OFFSET.interpolate(MODEL, 2.1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testHighOutOfRange() { INTERPOLATOR_NO_OFFSET.interpolate(MODEL, 10.); }