FunctionUtils { public static int getLowerBoundIndex(final double[] set, final double value) { final int n = set.length; if (value < set[0]) { return 0; } if (value > set[n - 1]) { return n - 1; } int index = Arrays.binarySearch(set, value); if (index >= 0) { return index; } if (index < 0) { index = -(index + 1); index--; } if (value == -0. && index < n - 1 && set[index + 1] == 0.) { ++index; } return index; } private  FunctionUtils(); static double square(final double x); static double cube(final double x); static int toTensorIndex(final int[] indices, final int[] dimensions); static int[] fromTensorIndex(final int index, final int[] dimensions); static double[] unique(final double[] in); static int[] unique(final int[] in); static int getLowerBoundIndex(final double[] set, final double value);  }
@Test public void getLowerBoundIndexTest() { int i = FunctionUtils.getLowerBoundIndex(new double[] {-2., -1. }, -0.); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {1., 2. }, -0.); assertEquals(i, 0); i = FunctionUtils.getLowerBoundIndex(new double[] {1., 2., 3. }, 2.5); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {1., 2., 3. }, 2.); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {1., 2., 3. }, -2.); assertEquals(i, 0); i = FunctionUtils.getLowerBoundIndex(new double[] {-2., -1., 0. }, -0.); assertEquals(i, 2); i = FunctionUtils.getLowerBoundIndex(new double[] {-2., -1., 0. }, 0.); assertEquals(i, 2); i = FunctionUtils.getLowerBoundIndex(new double[] {-2., -1., 0. }, -0.); assertEquals(i, 2); i = FunctionUtils.getLowerBoundIndex(new double[] {-2., -1., -0. }, -0.); assertEquals(i, 2); i = FunctionUtils.getLowerBoundIndex(new double[] {-1., 0., 1. }, -0.); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {-1., 0., 1. }, 0.); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {-1., -0., 1. }, 0.); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {-1., -0., 1. }, -0.); assertEquals(i, 1); i = FunctionUtils.getLowerBoundIndex(new double[] {0., 1., 2. }, -0.); assertEquals(i, 0); i = FunctionUtils.getLowerBoundIndex(new double[] {0., 1., 2. }, 0.); assertEquals(i, 0); i = FunctionUtils.getLowerBoundIndex(new double[] {-0., 1., 2. }, 0.); assertEquals(i, 0); i = FunctionUtils.getLowerBoundIndex(new double[] {-0., 1., 2. }, -0.); assertEquals(i, 0); }