ArrayUtils { public static int fuzzySearch(final float[] base, final float value, final boolean orGreater) { if (base == null || base.length == 0) return -1; if (value < base[0]) { if (orGreater) return 0; else return -1; } final int last = base.length - 1; if (value > base[last]) { if (orGreater) return -1; else return last; } return fuzzySearch(base, value, 0, base.length - 1, orGreater); }  static int[] fuzzyIntervalSearch(final float[] base, final float startValue, final float endValue); static int fuzzySearch(final float[] base, final float value, final boolean orGreater);  }
@Test public void testFuzzySearch() { final float[] base = new float[] { 1, 4, 4, 5, 7.3f, 8, 10, 23.4f, 23.4f, 34 }; final float[] nullBase = null; final float[] emptyBase = new float[0]; assertEquals(-1, ArrayUtils.fuzzySearch(nullBase, 5, true)); assertEquals(-1, ArrayUtils.fuzzySearch(emptyBase, 5, false)); assertEquals(0, ArrayUtils.fuzzySearch(base, 0.1f, true)); assertEquals(-1, ArrayUtils.fuzzySearch(base, 0.1f, false)); assertEquals(-1, ArrayUtils.fuzzySearch(base, 101, true)); assertEquals(base.length - 1, ArrayUtils.fuzzySearch(base, 101, false)); assertEquals(3, ArrayUtils.fuzzySearch(base, 5, true)); assertEquals(1, ArrayUtils.fuzzySearch(base, 4, true)); assertEquals(2, ArrayUtils.fuzzySearch(base, 4, false)); assertEquals(4, ArrayUtils.fuzzySearch(base, 7, true)); assertEquals(3, ArrayUtils.fuzzySearch(base, 7, false)); }