in uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java [535:603]
public static List<AnnotationFS> selectCovered(CAS cas, Type type,
AnnotationFS coveringAnnotation) {
int begin = coveringAnnotation.getBegin();
int end = coveringAnnotation.getEnd();
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
// withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> it = cas.getAnnotationIndex(type).iterator();
// Try to seek the insertion point.
it.moveTo(coveringAnnotation);
// If the insertion point is beyond the index, move back to the last.
if (!it.isValid()) {
it.moveToLast();
if (!it.isValid()) {
return list;
}
}
// Ignore type priorities by seeking to the first that has the same begin
boolean moved = false;
while (it.isValid() && (it.get()).getBegin() >= begin) {
it.moveToPrevious();
moved = true;
}
// If we moved, then we are now on one starting before the requested begin, so we have to
// move one ahead.
if (moved) {
it.moveToNext();
}
// If we managed to move outside the index, start at first.
if (!it.isValid()) {
it.moveToFirst();
}
// Skip annotations whose start is before the start parameter.
while (it.isValid() && (it.get()).getBegin() < begin) {
it.moveToNext();
}
boolean strict = true;
while (it.isValid()) {
AnnotationFS a = it.get();
// If the start of the current annotation is past the end parameter, we're done.
if (a.getBegin() > end) {
break;
}
it.moveToNext();
if (strict && a.getEnd() > end) {
continue;
}
assert (a.getBegin() >= coveringAnnotation.getBegin()) : "Illegal begin " + a.getBegin()
+ " in [" + coveringAnnotation.getBegin() + ".." + coveringAnnotation.getEnd() + "]";
assert (a.getEnd() <= coveringAnnotation.getEnd()) : "Illegal end " + a.getEnd() + " in ["
+ coveringAnnotation.getBegin() + ".." + coveringAnnotation.getEnd() + "]";
if (!a.equals(coveringAnnotation)) {
list.add(a);
}
}
return unmodifiableList(list);
}