in uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java [1290:1348]
public static List<AnnotationFS> selectFollowing(CAS cas, Type type, AnnotationFS anchor,
int count) {
requireAnnotationType(cas, type);
// Seek annotation in index
// withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> itr = cas.getAnnotationIndex(type).iterator();
itr.moveTo(anchor);
int anchorBegin = anchor.getBegin();
int anchorEnd = anchor.getEnd();
// When seeking forward, there is no need to check if the insertion point is beyond the
// index. If it was, there would be nothing beyond it that could be found and returned.
// The moveTo operation also does not yield an iterator being invalid because it points
// *before the first* index entry, at max it points *to the first* index entry, so this
// case also does not need to be handled.
// No need to do additional seeks here (as done in selectCovered) because the current method
// does not have to worry about type priorities - it never returns annotations that have
// the same offset as the reference annotation.
if (anchorBegin == anchorEnd) {
// zero-width annotations appear *after* larger annotations with the same start position in
// the index but the larger annotations are considered to be *following* the zero-width, so we
// have to look to the left for larger annotations...
if (itr.isValid()) {
itr.moveToPrevious();
while (itr.isValid() && itr.getNvc().getBegin() == anchorBegin) {
itr.moveToPrevious();
}
if (!itr.isValid()) {
itr.moveToFirst();
} else {
itr.moveToNext();
}
} else {
itr.moveToFirst();
}
}
// make sure we're past the end of the reference annotation
while (itr.isValid() && itr.get().getBegin() < anchorEnd) {
itr.moveToNext();
}
// add annotations from the iterator into the result list
List<AnnotationFS> followingAnnotations = new ArrayList<AnnotationFS>();
for (int i = 0; i < count && itr.isValid(); itr.moveToNext()) {
AnnotationFS cur = itr.get();
if (cur != anchor && cur.getBegin() >= anchorEnd) {
followingAnnotations.add(cur);
i++;
}
}
return followingAnnotations;
}