Package jodd.util
Class BinarySearch<E>
java.lang.Object
jodd.util.BinarySearch<E>
Binary search wrapper over any type of user-defined collection.
It provides a finder for given element, but also finder of first
and last index in range of equal elements.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intCompares element atindexposition with given object.intFinds index of given element or negative value if element is not found.intFinds index of given element in inclusive index range.intFinds very first index of given element or negative value if element is not found.intFinds very first index of given element in inclusive index range.intFinds very last index of given element or negative value if element is not found.intFinds very last index of given element in inclusive index range.protected abstract intReturns index of last element in wrapped collection.static <T extends Comparable>
BinarySearch<T> Creates binary search wrapper over a list of comparable elements.static <T> BinarySearch<T> on(List<T> list, Comparator<T> comparator) Creates binary search wrapper over a list with given comparator.static <T extends Comparable>
BinarySearch<T> on(T[] array) Creates binary search wrapper over an array.static <T> BinarySearch<T> on(T[] array, Comparator<T> comparator) Creates binary search wrapper over an array with given comparator.
-
Constructor Details
-
BinarySearch
public BinarySearch()
-
-
Method Details
-
on
Creates binary search wrapper over a list of comparable elements. -
on
Creates binary search wrapper over a list with given comparator. -
on
Creates binary search wrapper over an array. -
on
Creates binary search wrapper over an array with given comparator. -
compare
Compares element atindexposition with given object. -
getLastIndex
protected abstract int getLastIndex()Returns index of last element in wrapped collection. -
find
Finds index of given element or negative value if element is not found. -
find
Finds index of given element in inclusive index range. Returns negative value if element is not found. -
findFirst
Finds very first index of given element or negative value if element is not found. -
findFirst
Finds very first index of given element in inclusive index range. Returns negative value if element is not found. -
findLast
Finds very last index of given element or negative value if element is not found. -
findLast
Finds very last index of given element in inclusive index range. Returns negative value if element is not found.
-