(final char[][] haystack, final char[] key)
| 158 | } |
| 159 | |
| 160 | public static int binarySearch(final char[][] haystack, final char[] key) { |
| 161 | |
| 162 | int left = 0; |
| 163 | int right = haystack.length; |
| 164 | int middle; |
| 165 | |
| 166 | int compare = 0; |
| 167 | |
| 168 | while (right > left) { |
| 169 | middle = left + ((right - left) / 2); |
| 170 | |
| 171 | compare = |
| 172 | compareCharArrays( |
| 173 | key, 0, key.length, |
| 174 | haystack[middle], 0, haystack[middle].length); |
| 175 | |
| 176 | if (compare == 0) { |
| 177 | return middle; |
| 178 | } |
| 179 | |
| 180 | if (compare < 0) { |
| 181 | right = middle; |
| 182 | } else { |
| 183 | left = middle + 1; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Decrease the index by one. Thus, one can make the difference |
| 189 | * whether the exact word has been found when the returned index |
| 190 | * should be zero. |
| 191 | */ |
| 192 | return -left -1; |
| 193 | } |
| 194 | //endif |
| 195 | |
| 196 | // public static void toLowerCase( |
no test coverage detected