Use map.computeIfAbsent
Java 8 simplifies adding a value to a key in a map using a function.
Change-Id: Icb9632960d4c1c91bf6f9504cb6df78da757dfba
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/IssueExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/IssueExtractor.java
index d367cb0..75a1cc3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/IssueExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/IssueExtractor.java
@@ -57,7 +57,7 @@
}
/**
- * Helper funcion for {@link #getIssueIds(String, String)}.
+ * Helper function for {@link #getIssueIds(String, String)}.
*
* <p>Adds a text's issues for a given occurrence to the map returned by {@link
* #getIssueIds(String, String)}.
@@ -68,11 +68,7 @@
*/
private void addIssuesOccurrence(String text, String occurrence, Map<String, Set<String>> map) {
for (String issue : getIssueIds(text)) {
- Set<String> occurrences = map.get(issue);
- if (occurrences == null) {
- occurrences = Sets.newLinkedHashSet();
- map.put(issue, occurrences);
- }
+ Set<String> occurrences = map.computeIfAbsent(issue, k -> Sets.newLinkedHashSet());
occurrences.add(occurrence);
}
}