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
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.
- Since:
- 1.3
- Version:
- 1.3 (10/2014)
- Author:
- Grégory Mantelet (ARI)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BinarySearch()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
search
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.
- 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
protected abstract int compare(S searchItem, T arrayItem)
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.
-
-