T
- Type of items stored in the array.S
- Type of the item to search.protected abstract static class DBChecker.BinarySearch<T,S>
extends java.lang.Object
Implement the binary search algorithm over a sorted array.
The only difference with the standard implementation of Java is that this object lets perform research with a different type of object than the types of array items.
For that reason, the "compare" function must always be implemented.
Modifier | Constructor and Description |
---|---|
protected |
BinarySearch() |
Modifier and Type | Method and Description |
---|---|
protected abstract int |
compare(S searchItem,
T arrayItem)
Compare the search item and the array item.
|
int |
search(S searchItem,
T[] array)
Search the given item in the given array.
|
public int search(S searchItem, T[] array)
Search the given item in the given array.
In case the given object matches to several items of the array, this function will return the smallest index, pointing thus to the first of all matches.
searchItem
- Object for which a corresponding array item must be searched.array
- Array in which the given object must be searched.protected abstract int compare(S searchItem, T arrayItem)
searchItem
- Item whose a corresponding value must be found in the array.arrayItem
- An item of the array.