ArrayInterpolator1DDataBundle implements Interpolator1DDataBundle, Serializable { @Override public int getLowerBoundIndex(final Double value) { if (value < _keys[0]) { throw new IllegalArgumentException("Could not get lower bound index for " + value + ": lowest x-value is " + _keys[0]); } if (value > _keys[_n - 1]) { throw new IllegalArgumentException("Could not get lower bound index for " + value + ": highest x-value is " + _keys[_keys.length - 1]); } int index = Arrays.binarySearch(_keys, value); if (index >= 0) { return index; } if (index < 0) { index = -(index + 1); index--; } if (value == -0. && index < _n - 1 && _keys[index + 1] == 0.) { ++index; } return index; } ArrayInterpolator1DDataBundle(final double[] keys, final double[] values);  ArrayInterpolator1DDataBundle(final double[] keys, final double[] values, final boolean inputsSorted); @Override boolean containsKey(final Double key); @Override Double firstKey(); @Override Double firstValue(); @Override Double get(final Double key); @Override InterpolationBoundedValues getBoundedValues(final Double key); @Override double[] getKeys(); @Override int getLowerBoundIndex(final Double value); @Override Double getLowerBoundKey(final Double value); @Override double[] getValues(); @Override Double higherKey(final Double key); @Override Double higherValue(final Double key); @Override Double lastKey(); @Override Double lastValue(); @Override int size(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override void setYValueAtIndex(final int index, final double y);  }
@Test public void getLowerBoundIndexTest() { double[] yValues = new double[] {1., 2., 3. }; double[] xValues = new double[] {1., 2., 3. }; ArrayInterpolator1DDataBundle bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); int i = bundle.getLowerBoundIndex(2.5); assertEquals(1, i); i = bundle.getLowerBoundIndex(2.); assertEquals(1, i); xValues = new double[] {-2., -1., 0. }; bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); i = bundle.getLowerBoundIndex(0.); assertEquals(2, i); i = bundle.getLowerBoundIndex(-0.); assertEquals(2, i); xValues = new double[] {-2., -1., -0. }; bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); i = bundle.getLowerBoundIndex(0.); assertEquals(2, i); i = bundle.getLowerBoundIndex(-0.); assertEquals(2, i); xValues = new double[] {-1., 0., 1. }; bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); i = bundle.getLowerBoundIndex(0.); assertEquals(1, i); i = bundle.getLowerBoundIndex(-0.); assertEquals(1, i); xValues = new double[] {-1., -0., 1. }; bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); i = bundle.getLowerBoundIndex(0.); assertEquals(1, i); i = bundle.getLowerBoundIndex(-0.); assertEquals(1, i); xValues = new double[] {0., 1., 2. }; bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); i = bundle.getLowerBoundIndex(0.); assertEquals(0, i); i = bundle.getLowerBoundIndex(-0.); assertEquals(0, i); xValues = new double[] {-0., 1., 2. }; bundle = new ArrayInterpolator1DDataBundle(xValues, yValues); i = bundle.getLowerBoundIndex(0.); assertEquals(0, i); i = bundle.getLowerBoundIndex(-0.); assertEquals(0, i); }