AnnotationUtil { public static <T extends Annotation> void sort(List<T> annotations) { Collections.sort(annotations, new Comparator<T>() { public int compare(T o1, T o2) { if (o1.getBegin() != o2.getBegin()) return o1.getBegin() < o2.getBegin() ? -1 : 1; else if (o1.getEnd() != o2.getEnd()) return o1.getEnd() < o2.getEnd() ? -1 : 1; return 0; } }); }  static T selectFirstMatching(
      JCas jCas,
      Class<T> selectedType,
      Annotation annotation); static List<T> selectMatching(
      JCas jCas,
      Class<T> selectedType,
      Annotation annotation); static boolean contains(Annotation bigAnnotation, Annotation smallAnnotation); static boolean overlaps(Annotation annotation1, Annotation annotation2); static int size(Annotation annotation); static String getSurroundingText(
      JCas jCas,
      Annotation annotation,
      Class<TOKEN_TYPE> tokenClass,
      int numberOfTokens,
      boolean before); static void sort(List<T> annotations); static int[] getAnnotationsExtent(List<? extends Annotation> annotations);  }
@Test public void testSort() { List<Annotation> annotations = new ArrayList<Annotation>(); annotations.add(new Token(jCas, 19, 21)); annotations.add(new Token(jCas, 0, 15)); annotations.add(new Sentence(jCas, 0, 30)); annotations.add(new Sentence(jCas, 16, 30)); annotations.add(new Annotation(jCas, 1, 35)); annotations.add(new Annotation(jCas, 1, 34)); annotations.add(new Annotation(jCas, 1, 36)); AnnotationUtil.sort(annotations); assertEquals(0, annotations.get(0).getBegin()); assertEquals(15, annotations.get(0).getEnd()); assertEquals(0, annotations.get(1).getBegin()); assertEquals(30, annotations.get(1).getEnd()); assertEquals(1, annotations.get(2).getBegin()); assertEquals(34, annotations.get(2).getEnd()); assertEquals(1, annotations.get(3).getBegin()); assertEquals(35, annotations.get(3).getEnd()); assertEquals(1, annotations.get(4).getBegin()); assertEquals(36, annotations.get(4).getEnd()); assertEquals(16, annotations.get(5).getBegin()); assertEquals(30, annotations.get(5).getEnd()); assertEquals(19, annotations.get(6).getBegin()); assertEquals(21, annotations.get(6).getEnd()); }