AnnotationUtils { public static <T extends Annotation> Optional<T> getSingleCovered( final Class<T> clazz, final Annotation annotation) { final List<T> list = JCasUtil.selectCovered(clazz, annotation); if (list.isEmpty()) { return Optional.empty(); } else { return Optional.of(list.get(0)); } } private  AnnotationUtils(); static Optional<T> getSingleCovered(
      final Class<T> clazz, final Annotation annotation); static List<T> filterToTopLevelAnnotations(
      final Collection<T> annotations); static boolean isInBetween(
      final Annotation between, final Annotation source, final Annotation target); static boolean isCovering(final Annotation covering, final Annotation covered);  }
@Test public void testGetSingleCovered() { final Annotation a = new Annotation(jCas); a.setBegin(0); a.setEnd(4); final Optional<Annotation> single = AnnotationUtils.getSingleCovered(Annotation.class, a); Assert.assertEquals("012", single.get().getCoveredText()); }
@Test public void testGetSingleCoveredMissing() { final Annotation a = new Annotation(jCas); a.setBegin(1); a.setEnd(12); final Optional<Annotation> missing = AnnotationUtils.getSingleCovered(Annotation.class, a); Assert.assertFalse(missing.isPresent()); }