class 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);
    }
  }

  public  PolynomialInterpolator1D(final int degree);
  public  PolynomialInterpolator1D(final int degree, final int offset);

}