@Test public void testAfterLast() { assertThrows(VocabHunterException.class, () -> findClosest(AFTER_LAST)); }
public static int findClosest(final int requested, final int size, final IntPredicate test) { int nextLower = requested; int nextUpper = requested; while (nextLower >= 0 || nextUpper < size) { if (nextLower >= 0 && test.test(nextLower)) { return nextLower; } else if (nextUpper < size && test.test(nextUpper)) { return nextUpper; } --nextLower; ++nextUpper; } throw new VocabHunterException("Unable to find index match"); }
IndexTool { public static int findClosest(final int requested, final int size, final IntPredicate test) { int nextLower = requested; int nextUpper = requested; while (nextLower >= 0 || nextUpper < size) { if (nextLower >= 0 && test.test(nextLower)) { return nextLower; } else if (nextUpper < size && test.test(nextUpper)) { return nextUpper; } --nextLower; ++nextUpper; } throw new VocabHunterException("Unable to find index match"); } }
IndexTool { public static int findClosest(final int requested, final int size, final IntPredicate test) { int nextLower = requested; int nextUpper = requested; while (nextLower >= 0 || nextUpper < size) { if (nextLower >= 0 && test.test(nextLower)) { return nextLower; } else if (nextUpper < size && test.test(nextUpper)) { return nextUpper; } --nextLower; ++nextUpper; } throw new VocabHunterException("Unable to find index match"); } private  IndexTool(); }
IndexTool { public static int findClosest(final int requested, final int size, final IntPredicate test) { int nextLower = requested; int nextUpper = requested; while (nextLower >= 0 || nextUpper < size) { if (nextLower >= 0 && test.test(nextLower)) { return nextLower; } else if (nextUpper < size && test.test(nextUpper)) { return nextUpper; } --nextLower; ++nextUpper; } throw new VocabHunterException("Unable to find index match"); } private  IndexTool(); static int findClosest(final int requested, final int size, final IntPredicate test); }
IndexTool { public static int findClosest(final int requested, final int size, final IntPredicate test) { int nextLower = requested; int nextUpper = requested; while (nextLower >= 0 || nextUpper < size) { if (nextLower >= 0 && test.test(nextLower)) { return nextLower; } else if (nextUpper < size && test.test(nextUpper)) { return nextUpper; } --nextLower; ++nextUpper; } throw new VocabHunterException("Unable to find index match"); } private  IndexTool(); static int findClosest(final int requested, final int size, final IntPredicate test);  }