Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor code for adding annotations

  • Loading branch information...
commit 6a5c51c4661bf02ab41be04895f0c80ef85cfe96 1 parent 2ffdd21
@emk authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/buglinky/BugLinkyServlet.java
View
20 src/buglinky/BugLinkyServlet.java
@@ -72,20 +72,20 @@ private void addLinksToBlip(Blip blip) {
log.fine("Found a link: " + matcher.group());
Range range = new Range(matcher.start(), matcher.end());
String url = BUG_URL.concat(matcher.group(1));
- if (!isAnnotationAlreadyPresent(doc, range, url)) {
- log.fine("Making new link to " + url);
- doc.setAnnotation(range, LINK, url);
- }
+ maybeAnnotate(doc, range, LINK, url);
}
}
- /** Have we already added this annotation? */
- private boolean isAnnotationAlreadyPresent(TextView doc, Range range, String url) {
- for (Annotation annotation : doc.getAnnotations(range, LINK)) {
+ /** Add an annotation if it isn't already present. */
+ private void maybeAnnotate(TextView doc, Range range, String name, String value) {
+ // If this annotation is already present, give up now.
+ for (Annotation annotation : doc.getAnnotations(range, name)) {
if (annotation.getRange().equals(range) &&
- annotation.getValue().equals(url))
- return true;
+ annotation.getValue().equals(value))
+ return;
}
- return false;
+
+ log.fine("Making new link to " + value);
+ doc.setAnnotation(range, name, value);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.