public Collection<RutaBasic> getAllBasicsInWindow(AnnotationFS windowAnnotation) {
if (windowAnnotation.getBegin() >= windowAnnotation.getEnd()) {
return Collections.emptySet();
}
RutaBasic beginAnchor = getBeginAnchor(windowAnnotation.getBegin());
if (beginAnchor.getEnd() == windowAnnotation.getEnd()) {
Collection<RutaBasic> result = new ArrayList<RutaBasic>(1);
result.add(beginAnchor);
return result;
}
// was Java 6:
// RutaBasic endAnchor = getEndAnchor(windowAnnotation.getEnd());
// NavigableSet<RutaBasic> subSet = basics.subSet(beginAnchor, true, endAnchor, true);
Collection<RutaBasic> subSet = null;
if (windowAnnotation.getEnd() == cas.getDocumentAnnotation().getEnd()
&& windowAnnotation.getBegin() == 0) {
subSet = basics;
} else if (windowAnnotation.getEnd() == cas.getDocumentAnnotation().getEnd()) {
subSet = basics.tailSet(beginAnchor);
} else {
RutaBasic endAnchor1 = getCeiling(endAnchors, windowAnnotation.getEnd() + 1);
if (endAnchor1 != null) {
subSet = basics.subSet(beginAnchor, endAnchor1);
} else {
// hotfix for limited window stream with a window on the complete document
subSet = new LinkedList<RutaBasic>();
RutaBasic floor = getFloor(endAnchors, windowAnnotation.getEnd());
Collection<RutaBasic> subSetHead = basics.subSet(beginAnchor, floor);
RutaBasic endAnchorTail = endAnchors.get(windowAnnotation.getEnd());
subSet.addAll(subSetHead);
subSet.add(endAnchorTail);
}
}
return subSet;