package intervalstore.impl;
import java.util.List;
-import java.util.function.Function;
+import java.util.function.ToIntFunction;
+
+import intervalstore.api.IntervalI;
/**
* Provides a method to perform binary search of an ordered list for the first
*/
public final class BinarySearcher
{
+
+ public static ToIntFunction<IntervalI> fbegin = new ToIntFunction<IntervalI>()
+ {
+
+ @Override
+ public int applyAsInt(IntervalI value)
+ {
+ return value.getBegin();
+ }
+
+ };
+
+ public static ToIntFunction<IntervalI> fend = new ToIntFunction<IntervalI>()
+ {
+
+ @Override
+ public int applyAsInt(IntervalI value)
+ {
+ return value.getEnd();
+ }
+
+ };
+
private BinarySearcher()
{
}
* @return
* @see java.util.Collections#binarySearch(List, Object)
*/
- public static <T> int findFirst(List<? extends T> list,
- Function<T, Boolean> test)
+ public static <T> int findFirst(List<? extends T> list, int pos,
+ ToIntFunction<T> test)
{
int start = 0;
int end = list.size() - 1;
{
int mid = (start + end) / 2;
T entry = list.get(mid);
- boolean itsTrue = test.apply(entry);
+ boolean itsTrue = test.applyAsInt(entry) >= pos;
if (itsTrue)
{
matched = mid;