@Test public void testEqualInteger() { Integer[] elements = new Integer[] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; int index = BinaryObjectSearch.binSearch(elements, 6); assertEquals(-1, index); }
public static <T extends Comparable<? super T>> int binSearch(T[] data, T value) { int l = -1, h = data.length; while (l + 1 != h) { int m = l + (h - l) / 2; int compare = data[m].compareTo(value); if (compare < 0) { l = m; } else if (compare > 0) { h = m; } else { return m; } } return NOT_FOUND; }
BinaryObjectSearch { public static <T extends Comparable<? super T>> int binSearch(T[] data, T value) { int l = -1, h = data.length; while (l + 1 != h) { int m = l + (h - l) / 2; int compare = data[m].compareTo(value); if (compare < 0) { l = m; } else if (compare > 0) { h = m; } else { return m; } } return NOT_FOUND; } }
BinaryObjectSearch { public static <T extends Comparable<? super T>> int binSearch(T[] data, T value) { int l = -1, h = data.length; while (l + 1 != h) { int m = l + (h - l) / 2; int compare = data[m].compareTo(value); if (compare < 0) { l = m; } else if (compare > 0) { h = m; } else { return m; } } return NOT_FOUND; }  }
BinaryObjectSearch { public static <T extends Comparable<? super T>> int binSearch(T[] data, T value) { int l = -1, h = data.length; while (l + 1 != h) { int m = l + (h - l) / 2; int compare = data[m].compareTo(value); if (compare < 0) { l = m; } else if (compare > 0) { h = m; } else { return m; } } return NOT_FOUND; }  static int binSearch(T[] data, T value); }
BinaryObjectSearch { public static <T extends Comparable<? super T>> int binSearch(T[] data, T value) { int l = -1, h = data.length; while (l + 1 != h) { int m = l + (h - l) / 2; int compare = data[m].compareTo(value); if (compare < 0) { l = m; } else if (compare > 0) { h = m; } else { return m; } } return NOT_FOUND; }  static int binSearch(T[] data, T value); static final int NOT_FOUND; }