* Test deleting FSs from indexes.
*/
public void testDelete() {
// Create a bunch of FSs.
AnnotationFS[] fsArray = new AnnotationFS[100];
FSIndexRepository ir = this.cas.getIndexRepository();
for (int i = 0; i < fsArray.length; i++) {
fsArray[i] = this.cas.createAnnotation(this.tokenType, i * 5, (i * 5) + 4);
ir.addFS(fsArray[i]);
}
FSIndex<FeatureStructure> setIndex = this.cas.getIndexRepository().getIndex(
CASTestSetup.ANNOT_SET_INDEX, this.tokenType);
FSIterator<FeatureStructure> setIt = setIndex.iterator();
FSIndex<AnnotationFS> sortedIndex = this.cas.getAnnotationIndex(this.tokenType);
FSIterator<AnnotationFS> sortedIt = sortedIndex.iterator();
FSIndex<FeatureStructure> bagIndex = ir.getIndex(CASTestSetup.ANNOT_BAG_INDEX, this.tokenType);
FSIterator<FeatureStructure> bagIt = bagIndex.iterator();
// For each index, check that the FSs are actually in the index.
for (int i = 0; i < fsArray.length; i++) {
setIt.moveTo(fsArray[i]);
assertTrue(setIt.isValid());
assertTrue(setIt.get().equals(fsArray[i]));
bagIt.moveTo(fsArray[i]);
assertTrue(bagIt.isValid());
assertTrue(bagIt.get().equals(fsArray[i]));
sortedIt.moveTo(fsArray[i]);
assertTrue(sortedIt.isValid());
assertTrue(sortedIt.get().equals(fsArray[i]));
}
// Remove an annotation, then add it again. Try setting the iterators to
// that FS. The iterator should either be invalid, or point to a
// different FS.
for (int i = 0; i < fsArray.length; i++) {
ir.removeFS(fsArray[i]);
setIt.moveTo(fsArray[i]);
if (setIt.isValid()) {
int oldRef = this.cas.ll_getFSRef(fsArray[i]);
int newRef = this.cas.ll_getFSRef(setIt.get());
assertTrue(oldRef != newRef);
assertTrue(!setIt.get().equals(fsArray[i]));
}
bagIt.moveTo(fsArray[i]);
if (bagIt.isValid()) {
assertTrue(!bagIt.get().equals(fsArray[i]));
}
sortedIt.moveTo(fsArray[i]);
if (sortedIt.isValid()) {
assertTrue(!sortedIt.get().equals(fsArray[i]));
}
ir.addFS(fsArray[i]);
}
// Remove all annotations.
for (int i = 0; i < fsArray.length; i++) {
ir.removeFS(fsArray[i]);
}
// All iterators should be invalidated when being reset.
bagIt.moveToFirst();
assertFalse(bagIt.isValid());
setIt.moveToFirst();