org.onebusaway.transit_data_federation.impl.time
Class GenericBinarySearch

java.lang.Object
  extended by org.onebusaway.transit_data_federation.impl.time.GenericBinarySearch

public class GenericBinarySearch
extends Object

Generic binary search that can accepts lists of Java objects that can be adapted to a double value for searching.

Author:
bdferris

Nested Class Summary
static interface GenericBinarySearch.IndexAdapter<T>
           
static interface GenericBinarySearch.ValueAdapter<T>
           
 
Constructor Summary
GenericBinarySearch()
           
 
Method Summary
static
<T> int
search(List<T> elements, double targetValue, GenericBinarySearch.ValueAdapter<T> valueAdapter)
          Return an index into the element list such that if a new element with the specified target value was inserted into the list at the specified index, the list would remain in sorted order with respect to the GenericBinarySearch.ValueAdapter
static
<T> int
search(T elements, int size, double targetValue, GenericBinarySearch.IndexAdapter<T> valueAdapter)
          Return an index into the element list such that if a new element with the specified target value was inserted into the list at the specified index, the list would remain in sorted order with respect to the GenericBinarySearch.ValueAdapter
static
<T> int
searchRange(T elements, int indexFrom, int indexTo, double targetValue, GenericBinarySearch.IndexAdapter<T> valueAdapter)
          Return an index into the element list such that if a new element with the specified target value was inserted into the list at the specified index, the list would remain in sorted order with respect to the GenericBinarySearch.IndexAdapter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericBinarySearch

public GenericBinarySearch()
Method Detail

search

public static <T> int search(List<T> elements,
                             double targetValue,
                             GenericBinarySearch.ValueAdapter<T> valueAdapter)
Return an index into the element list such that if a new element with the specified target value was inserted into the list at the specified index, the list would remain in sorted order with respect to the GenericBinarySearch.ValueAdapter

Parameters:
elements - a list of objects, sorted in the order appropriate to the GenericBinarySearch.ValueAdapter
targetValue - target value to search for
valueAdapter - adapter to convert the input element type into a double value
Returns:

search

public static <T> int search(T elements,
                             int size,
                             double targetValue,
                             GenericBinarySearch.IndexAdapter<T> valueAdapter)
Return an index into the element list such that if a new element with the specified target value was inserted into the list at the specified index, the list would remain in sorted order with respect to the GenericBinarySearch.ValueAdapter

Parameters:
elements - a list of objects, sorted in the order appropriate to the GenericBinarySearch.ValueAdapter
targetValue - target value to search for
valueAdapter - adapter to convert the input element type into a double value
Returns:

searchRange

public static <T> int searchRange(T elements,
                                  int indexFrom,
                                  int indexTo,
                                  double targetValue,
                                  GenericBinarySearch.IndexAdapter<T> valueAdapter)
Return an index into the element list such that if a new element with the specified target value was inserted into the list at the specified index, the list would remain in sorted order with respect to the GenericBinarySearch.IndexAdapter

Parameters:
elements - a collection of objects, sorted in the order appropriate to the GenericBinarySearch.IndexAdapter
indexFrom - starting index range
indexTo - ending index range
targetValue - target value to search for
valueAdapter - adapter to convert the input element type into a double value
Returns:


Copyright © 2011 OneBusAway. All Rights Reserved.