in uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java [1022:1044]
public static AnnotationFS selectByIndex(CAS cas, Type type, int index) {
requireAnnotationType(cas, type);
// withSnapshotIterators() not needed here since we return only one result
FSIterator<AnnotationFS> i = cas.getAnnotationIndex(type).iterator();
int n = index;
i.moveToFirst();
if (n > 0) {
while (n > 0 && i.isValid()) {
i.moveToNext();
n--;
}
}
if (n < 0) {
i.moveToLast();
while (n < -1 && i.isValid()) {
i.moveToPrevious();
n++;
}
}
return i.isValid() ? i.get() : null;
}