Comparators { public static Comparator<Long> longOverlapComparator() { return (o1, o2) -> { int b1 = (int)(o1 >> 32); int e1 = (int)(o1 >> 0); int b2 = (int)(o2 >> 32); int e2 = (int)(o2 >> 0); if ((b1 <= b2) && (e1 >= e2)) { return 0; } else if ((b1 >= b2) && (e1 <= e2)) { return 0; } else if ((b1 < e2) && (e1 > e2)) { return 0; } else if ((b1 < b2) && (e1 > b2)) { return 0; } return b1 - b2; }; }  static Comparator<T> exactOffsetMatchComparator(); static Comparator<T> overlapComparator(); static Comparator<T> beginOffsetComparator(); static Comparator<T> endOffsetComparator(); static Comparator<Long> longOverlapComparator();  }
@Test public void testLongOverlapComparator() throws Exception { JCas cas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-all-types"); Annotation a = new Annotation(cas, 1234, 9876); long l = (5000l << 32) | 15000; assertEquals(0, Comparators.longOverlapComparator().compare(l, TermGenerators.longOffsetTermGenerator().asKey(a))); l = (50l << 32) | 5000; assertEquals(0, Comparators.longOverlapComparator().compare(l, TermGenerators.longOffsetTermGenerator().asKey(a))); l = (2000l << 32) | 5000; assertEquals(0, Comparators.longOverlapComparator().compare(l, TermGenerators.longOffsetTermGenerator().asKey(a))); l = (50l << 32) | 15000; assertEquals(0, Comparators.longOverlapComparator().compare(l, TermGenerators.longOffsetTermGenerator().asKey(a))); l = (10l << 32) | 17; assertTrue(0 > Comparators.longOverlapComparator().compare(l, TermGenerators.longOffsetTermGenerator().asKey(a))); l = (10000l << 32) | 15000; assertTrue(0 < Comparators.longOverlapComparator().compare(l, TermGenerators.longOffsetTermGenerator().asKey(a))); }