@Test public void testBinarySearch() throws Exception { JCas cas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-all-types"); cas.setDocumentText("token1 token2 token3 token4"); Token t1 = new Token(cas, 0, 6); Token t2 = new Token(cas, 7, 13); Token t3 = new Token(cas, 14, 20); Token t4 = new Token(cas, 21, 27); List<Token> list = Arrays.asList(t1, t2, t3, t4); int pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 0); assertEquals(0, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 7); assertEquals(1, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 14); assertEquals(2, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 21); assertEquals(3, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), -1); assertEquals(-1, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 5); assertEquals(-2, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 10); assertEquals(-3, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 15); assertEquals(-4, pos); pos = JCoReTools.binarySearch(list, t -> t.getBegin(), 25); assertEquals(-5, pos); }
public static <T extends Annotation, R extends Comparable<R>> int binarySearch(List<T> annotations, Function<T, R> comparisonValueFunction, R searchValue) { return binarySearch(annotations, comparisonValueFunction, searchValue, 0, annotations.size() - 1); }
JCoReTools { public static <T extends Annotation, R extends Comparable<R>> int binarySearch(List<T> annotations, Function<T, R> comparisonValueFunction, R searchValue) { return binarySearch(annotations, comparisonValueFunction, searchValue, 0, annotations.size() - 1); } }
JCoReTools { public static <T extends Annotation, R extends Comparable<R>> int binarySearch(List<T> annotations, Function<T, R> comparisonValueFunction, R searchValue) { return binarySearch(annotations, comparisonValueFunction, searchValue, 0, annotations.size() - 1); }  }
JCoReTools { public static <T extends Annotation, R extends Comparable<R>> int binarySearch(List<T> annotations, Function<T, R> comparisonValueFunction, R searchValue) { return binarySearch(annotations, comparisonValueFunction, searchValue, 0, annotations.size() - 1); }  static FSArray addToFSArray(final FSArray array, final FeatureStructure newElement); static FSArray addToFSArray(final FSArray array, final FeatureStructure newElement, final int additionSize); static FSArray addToFSArray(final FSArray inputArray,
                                       final Collection<? extends FeatureStructure> newElements); static FSArray copyFSArray(FSArray array); static StringArray newStringArray(JCas jCas, String... elements); static StringArray addToStringArray(StringArray array, String element); static StringArray addToStringArray(StringArray array, String[] elements); static void printFSArray(FSArray array); static void printAnnotationIndex(JCas jCas, int type); static String getDocId(JCas aJCas); static void deserializeXmi(CAS cas, InputStream is, int attributeBufferSize); static int binarySearch(List<T> annotations,
                                                                                   Function<T, R> comparisonValueFunction, R searchValue); static int binarySearch(List<T> annotations,
                                                                                   Function<T, R> comparisonValueFunction, R searchValue, int from, int to); static InputStream resolveExternalResourceGzipInputStream(DataResource resource); }
JCoReTools { public static <T extends Annotation, R extends Comparable<R>> int binarySearch(List<T> annotations, Function<T, R> comparisonValueFunction, R searchValue) { return binarySearch(annotations, comparisonValueFunction, searchValue, 0, annotations.size() - 1); }  static FSArray addToFSArray(final FSArray array, final FeatureStructure newElement); static FSArray addToFSArray(final FSArray array, final FeatureStructure newElement, final int additionSize); static FSArray addToFSArray(final FSArray inputArray,
                                       final Collection<? extends FeatureStructure> newElements); static FSArray copyFSArray(FSArray array); static StringArray newStringArray(JCas jCas, String... elements); static StringArray addToStringArray(StringArray array, String element); static StringArray addToStringArray(StringArray array, String[] elements); static void printFSArray(FSArray array); static void printAnnotationIndex(JCas jCas, int type); static String getDocId(JCas aJCas); static void deserializeXmi(CAS cas, InputStream is, int attributeBufferSize); static int binarySearch(List<T> annotations,
                                                                                   Function<T, R> comparisonValueFunction, R searchValue); static int binarySearch(List<T> annotations,
                                                                                   Function<T, R> comparisonValueFunction, R searchValue, int from, int to); static InputStream resolveExternalResourceGzipInputStream(DataResource resource); static final int DEFAULT_ADDITION_SIZE; }