Skip to content

Commit

Permalink
Allow existing annotation to be larger than the current one
Browse files Browse the repository at this point in the history
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 203e16e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/buglinky/BugLinkyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.