Package jodd.util
Class BinarySearch<E>
- java.lang.Object
-
- jodd.util.BinarySearch<E>
-
public abstract class BinarySearch<E> extends java.lang.ObjectBinary 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 Constructor Description BinarySearch()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract intcompare(int index, E element)Compares element atindexposition with given object.intfind(E element)Finds index of given element or negative value if element is not found.intfind(E element, int low, int high)Finds index of given element in inclusive index range.intfindFirst(E o)Finds very first index of given element or negative value if element is not found.intfindFirst(E o, int low, int high)Finds very first index of given element in inclusive index range.intfindLast(E o)Finds very last index of given element or negative value if element is not found.intfindLast(E o, int low, int high)Finds very last index of given element in inclusive index range.protected abstract intgetLastIndex()Returns index of last element in wrapped collection.static <T extends java.lang.Comparable>
BinarySearch<T>on(java.util.List<T> list)Creates binary search wrapper over a list of comparable elements.static <T> BinarySearch<T>on(java.util.List<T> list, java.util.Comparator<T> comparator)Creates binary search wrapper over a list with given comparator.static <T extends java.lang.Comparable>
BinarySearch<T>on(T[] array)Creates binary search wrapper over an array.static <T> BinarySearch<T>on(T[] array, java.util.Comparator<T> comparator)Creates binary search wrapper over an array with given comparator.
-
-
-
Method Detail
-
on
public static <T extends java.lang.Comparable> BinarySearch<T> on(java.util.List<T> list)
Creates binary search wrapper over a list of comparable elements.
-
on
public static <T> BinarySearch<T> on(java.util.List<T> list, java.util.Comparator<T> comparator)
Creates binary search wrapper over a list with given comparator.
-
on
public static <T extends java.lang.Comparable> BinarySearch<T> on(T[] array)
Creates binary search wrapper over an array.
-
on
public static <T> BinarySearch<T> on(T[] array, java.util.Comparator<T> comparator)
Creates binary search wrapper over an array with given comparator.
-
compare
protected abstract int compare(int index, E element)Compares element atindexposition with given object.
-
getLastIndex
protected abstract int getLastIndex()
Returns index of last element in wrapped collection.
-
find
public int find(E element)
Finds index of given element or negative value if element is not found.
-
find
public int find(E element, int low, int high)
Finds index of given element in inclusive index range. Returns negative value if element is not found.
-
findFirst
public int findFirst(E o)
Finds very first index of given element or negative value if element is not found.
-
findFirst
public int findFirst(E o, int low, int high)
Finds very first index of given element in inclusive index range. Returns negative value if element is not found.
-
findLast
public int findLast(E o)
Finds very last index of given element or negative value if element is not found.
-
findLast
public int findLast(E o, int low, int high)
Finds very last index of given element in inclusive index range. Returns negative value if element is not found.
-
-