*/
// HACK(danilatos): This code is inefficient and does not belong in indexed document.
private List<AnnotationEvent> deleteAnnotations(int size) {
final List<AnnotationEvent> events = new ArrayList<AnnotationEvent>();
final StringSet open = CollectionUtils.createStringSet();
final StringMap<String> deletionInherit = CollectionUtils.createStringMap();
deletionValues.each(new ReadableStringMap.ProcV<String>() {
@Override
public void apply(String key, String value) {
deletionInherit.put(key, value);
}
});
final int start = currentLocation;
final int end = currentLocation + size;
for (AnnotationInterval<String> i : annotationIntervals(start, end, null)) {
assert i.end() > start;
assert i.start() < end;
final int realStart = Math.max(start, i.start());
deletionInherit.each(new ReadableStringMap.ProcV<String>() {
@Override
public void apply(String key, String value) {
events.add(
new AnnotationStartEvent(realStart, key, getAnnotation(realStart, key)));
open.add(key);
}
});
i.annotations().each(new ReadableStringMap.ProcV<String>() {
@Override
public void apply(String key, String value) {
if (!deletionInherit.containsKey(key)) {
events.add(
new AnnotationStartEvent(realStart, key, value));
open.add(key);
}
}
});
}
// Produce endAnnotation calls for every annotation at the end.
open.each(new StringSet.Proc() {
@Override
public void apply(String key) {
events.add(new AnnotationEndEvent(end, key));
}
});