Class GenericBinarySearch
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description static interface
GenericBinarySearch.IndexAdapter<T>
static interface
GenericBinarySearch.ValueAdapter<T>
-
Constructor Summary
Constructors Constructor Description GenericBinarySearch()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 theGenericBinarySearch.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 theGenericBinarySearch.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 theGenericBinarySearch.IndexAdapter
-
-
-
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 theGenericBinarySearch.ValueAdapter
- Parameters:
elements
- a list of objects, sorted in the order appropriate to theGenericBinarySearch.ValueAdapter
targetValue
- target value to search forvalueAdapter
- 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 theGenericBinarySearch.ValueAdapter
- Parameters:
elements
- a list of objects, sorted in the order appropriate to theGenericBinarySearch.ValueAdapter
targetValue
- target value to search forvalueAdapter
- 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 theGenericBinarySearch.IndexAdapter
- Parameters:
elements
- a collection of objects, sorted in the order appropriate to theGenericBinarySearch.IndexAdapter
indexFrom
- starting index rangeindexTo
- ending index rangetargetValue
- target value to search forvalueAdapter
- adapter to convert the input element type into a double value- Returns:
-
-