Package adql.db
Class DBChecker.BinarySearch<T,S>
java.lang.Object
adql.db.DBChecker.BinarySearch<T,S>
- Type Parameters:
T
- Type of items stored in the array.S
- Type of the item to search.
- Enclosing class:
- DBChecker
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.
- Since:
- 1.3
- Version:
- 1.3 (10/2014)
- Author:
- Grégory Mantelet (ARI)
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
BinarySearch
protected BinarySearch()
-
-
Method Details
-
search
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.
- Parameters:
searchItem
- Object for which a corresponding array item must be searched.array
- Array in which the given object must be searched.- Returns:
- The array index of the first item of all matches.
-
compare
Compare the search item and the array item.- Parameters:
searchItem
- Item whose a corresponding value must be found in the array.arrayItem
- An item of the array.- Returns:
- Negative value if searchItem is less than arrayItem, 0 if they are equals, or a positive value if searchItem is greater.
-