Permalink
Browse files

Allow existing annotation to be larger than the current one

When detecting whether an annotation already exists, accept any
annotation with the correct name and value which includes at least the
desired range. In this case, adding a new annotation does nothing except
for generate useless network traffic.
  • Loading branch information...
emk committed Aug 29, 2009
1 parent 4f88828 commit 203e16e6fa5186603dfe67e6edcaa7b2ef54dffd
Showing with 15 additions and 5 deletions.
  1. +15 −5 src/buglinky/BugLinkyServlet.java
@@ -84,17 +84,27 @@ private void addLinksToBlip(Blip blip) {
}
}
- /** Add an annotation if it isn't already present. */
+ /**
+ * Add an annotation if it isn't already present.
+ *
+ * The Wave Robot API does not currently filter out duplicate annotation
+ * requests, which causes extra network traffic and more possibilities for
+ * nasty bot loops. So we do this screening on our end.
+ */
private void maybeAnnotate(TextView doc, Range range, String name,
String value) {
- // If this annotation is already present, give up now.
+ // If this annotation is already present, give up now. Note that
+ // we allow the existing annotation to be bigger than the one we're
+ // creating, because in that case, setting the new annotation won't
+ // do anything useful.
for (Annotation annotation : doc.getAnnotations(range, name)) {
- if (annotation.getRange().equals(range) &&
- annotation.getValue().equals(value))
+ if (annotation.getValue().equals(value) &&
+ annotation.getRange().getStart() <= range.getStart() &&
+ range.getEnd() <= annotation.getRange().getEnd())
return;
}
- LOG.fine("Making new link to " + value);
+ LOG.fine("Annotating with " + value);
doc.setAnnotation(range, name, value);
}
}

0 comments on commit 203e16e

Please sign in to comment.