in uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java [1102:1168]
private boolean adjustForStrictOrCoveringAndBoundSkip(boolean oneStepOnly) {
boolean wentBack = false;
boolean lastSeenWasEqualToBounds = false;
switch (boundsUse) {
case coveredBy:
// We need to try seeking backwards because we may have skipped covered annotations which
// start within the selection range but do not end within it.
while (it.isValid()
&& (equalToBounds(it.getNvc()) || (oneStepOnly ? !coveredByBounds(it.getNvc())
: it.getNvc().getBegin() >= boundBegin))) {
it.moveToPreviousNvc();
wentBack = true;
}
break;
case covering:
// because this method is move to previous, the position cannot be on the bounds.
// handle skipping cases where the end is < boundEnd
while (it.isValid()
&& (equalToBounds(it.getNvc())
|| (oneStepOnly
? it.getNvc().getBegin() <= boundBegin
&& (it.getNvc().getEnd() < boundEnd
|| (it.getNvc().getEnd() == boundEnd && lto != null
&& lto.lessThan(it.getNvc()._getTypeImpl(),
boundType)))
: it.getNvc().getEnd() < boundEnd))) {
// FIXME: I can't really wrap my head around the logic of "maybeMoveToPrevBounded()"
// Possibly this is buggy and should be changed to t.moveToPreviousNvc() - after all, we
// do have the backing up logic below in case the iterator becomes invalid...
maybeMoveToPrevBounded();
wentBack = true;
}
break;
case sameBeginEnd:
while (it.isValid() && ((lastSeenWasEqualToBounds = equalToBounds(it.getNvc()))
|| (!oneStepOnly && (it.getNvc().getBegin() > boundBegin
|| (it.getNvc().getBegin() == boundBegin
&& it.getNvc().getEnd() <= boundEnd))))) {
it.moveToPreviousNvc(); // can be multiple equal to bounds
wentBack = true;
}
break;
default: // same as no bounds case
}
if (wentBack) {
if (!it.isValid()) {
if (!oneStepOnly || lastSeenWasEqualToBounds) {
it.moveToFirstNoReinit();
}
} else {
if (!oneStepOnly && it.getNvc().getBegin() < boundingAnnot.getBegin()) {
it.moveToNextNvc();
} else if (boundsUse == BoundsUse.sameBeginEnd
&& (oneStepOnly ? it.getNvc().getBegin() != boundingAnnot.getBegin()
: it.getNvc().getBegin() == boundingAnnot.getBegin())
&& it.getNvc().getEnd() != boundingAnnot.getEnd()) {
it.moveToNextNvc();
}
}
}
return wentBack;
}