X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fintervalstore%2Fimpl%2FBinarySearcher.java;h=6c598ceac51b52d036cdcdfd525260652f44139d;hb=b74cdec4b07000bee431a7cca86a948f44d3ffbe;hp=1086e9149b472b5fe3d1697dcc3b1d9a43480d8a;hpb=5bf9d1929f1821170e5052976cf4e7435fb29ab4;p=jalview.git diff --git a/src/intervalstore/impl/BinarySearcher.java b/src/intervalstore/impl/BinarySearcher.java index 1086e91..6c598ce 100644 --- a/src/intervalstore/impl/BinarySearcher.java +++ b/src/intervalstore/impl/BinarySearcher.java @@ -32,7 +32,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 @@ -42,6 +44,29 @@ import java.util.function.Function; */ public final class BinarySearcher { + + public static ToIntFunction fbegin = new ToIntFunction() + { + + @Override + public int applyAsInt(IntervalI value) + { + return value.getBegin(); + } + + }; + + public static ToIntFunction fend = new ToIntFunction() + { + + @Override + public int applyAsInt(IntervalI value) + { + return value.getEnd(); + } + + }; + private BinarySearcher() { } @@ -63,8 +88,8 @@ public final class BinarySearcher * @return * @see java.util.Collections#binarySearch(List, Object) */ - public static int findFirst(List list, - Function test) + public static int findFirst(List list, int pos, + ToIntFunction test) { int start = 0; int end = list.size() - 1; @@ -74,7 +99,7 @@ public final class BinarySearcher { 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;