jodd.util
Class BinarySearch<E>

java.lang.Object
  extended by jodd.util.BinarySearch<E>

public abstract class BinarySearch<E>
extends java.lang.Object

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
BinarySearch()
           
 
Method Summary
protected abstract  int compare(int index, E element)
          Compares element at index position with given object.
 int find(E element)
          Finds index of given element or negative value if element is not found.
 int find(E element, int low)
           
 int find(E element, int low, int high)
          Finds index of given element in inclusive index range.
 int findFirst(E o)
          Finds very first index of given element or negative value if element is not found.
 int findFirst(E o, int low)
           
 int findFirst(E o, int low, int high)
          Finds very first index of given element in inclusive index range.
 int findLast(E o)
          Finds very last index of given element or negative value if element is not found.
 int findLast(E o, int low)
           
 int findLast(E o, int low, int high)
          Finds very last index of given element in inclusive index range.
static
<T extends java.lang.Comparable>
BinarySearch<T>
forList(java.util.List<T> list)
          Creates binary search wrapper over a list of comparable elements.
static
<T> BinarySearch<T>
forList(java.util.List<T> list, java.util.Comparator<T> comparator)
          Creates binary search wrapper over a list with given comparator.
protected abstract  int getLastIndex()
          Returns index of last element in wrapped collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinarySearch

public BinarySearch()
Method Detail

forList

public static <T extends java.lang.Comparable> BinarySearch<T> forList(java.util.List<T> list)
Creates binary search wrapper over a list of comparable elements.


forList

public static <T> BinarySearch<T> forList(java.util.List<T> list,
                                          java.util.Comparator<T> comparator)
Creates binary search wrapper over a list with given comparator.


compare

protected abstract int compare(int index,
                               E element)
Compares element at index position 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)

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)

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)

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.



Copyright © 2003-2012 Jodd Team