AnnotationUtils { public static int overlapLength(Annotation first, Annotation second) { if (!overlap(first, second)) { return 0; } return Math.min(first.getEnd(), second.getEnd()) - Math.max(first.getBegin(), second.getBegin()); } private  AnnotationUtils(); static String toPrettyString(AnnotationFS anno); static String textBefore(AnnotationFS anno, int contextCharNum); static String textAfter(AnnotationFS anno, int contextCharNum); static int length(Annotation anno); static boolean isEmpty(AnnotationFS anno); static boolean overlap(AnnotationFS first, AnnotationFS second); static int overlapLength(Annotation first, Annotation second); static FSIterator<T> getOverlapping(CAS cas,
                                                                            FSIterator<T> iter, AnnotationFS targetAnno); @Deprecated static void fill(FSIterator<FST> srcIter,
                                                           Collection<FST> destCol); @Deprecated static List<FST> toList(FSIterator<FST> iter); @Deprecated static Set<FST> toSet(FSIterator<FST> iter); static Set<FST> toLinkedHashSet(FSIterator<FST> iter); @SuppressWarnings("unchecked") static List<FST> toList(FSArray casArray,
                                                                  Class<FST> fstClass); @SuppressWarnings("unchecked") static T getFeatureValueSafe(
            FeatureStructure srcFS, String featureName); static String getStringValue(JCas cas, Type type, Feature feature); static String getStringValue(CAS cas, Type type, Feature feature); @SuppressWarnings("unchecked") static A getSingleAnnotation(JCas cas, Class<A> typeJCasClass); static FSMatchConstraint getCoveredConstraint(AnnotationFS coveringAnnotation); static OverlapIndex<A> createOverlapIndex(Iterator<A> srcIter); @SuppressWarnings("unchecked") static T create(JCas jCas, int begin, int end, Class<T> cls); static Function<AnnotationFS, String> coveredTextFunction(); static A findByCoveredText(JCas jCas, Class<A> annoClass, final String coveredText); static boolean isBefore(AnnotationFS first, AnnotationFS second);  }
@Test public void testOverlapLength() throws ResourceInitializationException, CASException { JCas cas = CasCreationUtils.createCas( TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null) .getJCas(); Annotation firstAnno = new Annotation(cas); Annotation secondAnno = new Annotation(cas); for (Table.Cell<Offsets, Offsets, Integer> testCell : overlapTestTable.cellSet()) { firstAnno.setBegin(testCell.getRowKey().getBegin()); firstAnno.setEnd(testCell.getRowKey().getEnd()); secondAnno.setBegin(testCell.getColumnKey().getBegin()); secondAnno.setEnd(testCell.getColumnKey().getEnd()); assertEquals("overlapLength", AnnotationUtils.overlapLength(firstAnno, secondAnno), testCell.getValue().longValue()); } }