]> source.dussan.org Git - sonarqube.git/commitdiff
Add Issues.componentById() helper
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Mar 2014 14:28:42 +0000 (15:28 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Mar 2014 14:29:48 +0000 (15:29 +0100)
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssues.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java

index 7e6fc88e20395ea478974c0d7c66f9891bd89b77..0b7de9482266d9d08343fe388125e4dba6c234ec 100644 (file)
@@ -51,6 +51,9 @@ public interface Issues {
   @CheckForNull
   Component component(Issue issue);
 
+  @CheckForNull
+  Component componentById(long id);
+
   Collection<Component> projects();
 
   @CheckForNull
index e4693e370e47aa7b57d49463368d80513597e01f..2b76fa74634c3d465194a820f613d3ddac6787db 100644 (file)
@@ -40,7 +40,7 @@ public class DefaultIssues implements Issues {
   private final List<Issue> list = new ArrayList<Issue>();
   private final Map<String, Rule> rulesByKey = new HashMap<String, Rule>();
   private final Map<String, User> usersByKey = new HashMap<String, User>();
-  private final Map<String, Component> componentsByKey = new HashMap<String, Component>();
+  private final Map<Long, Component> componentsById = new HashMap<Long, Component>();
   private final Map<String, Component> projectsByKey = new HashMap<String, Component>();
   private final Map<String, ActionPlan> actionPlansByKey = new HashMap<String, ActionPlan>();
   private Paging paging;
@@ -72,12 +72,17 @@ public class DefaultIssues implements Issues {
   }
 
   public Collection<Component> components() {
-    return componentsByKey.values();
+    return componentsById.values();
   }
 
   @CheckForNull
   public Component component(Issue issue) {
-    return componentsByKey.get(issue.componentKey());
+    return componentsById.get(issue.componentId());
+  }
+
+  @CheckForNull
+  public Component componentById(long id) {
+    return componentsById.get(id);
   }
 
   public Collection<Component> projects() {
@@ -128,7 +133,7 @@ public class DefaultIssues implements Issues {
   }
 
   DefaultIssues addComponent(Component c) {
-    componentsByKey.put(c.key(), c);
+    componentsById.put(c.id(), c);
     return this;
   }
 
index 2ea31630d82b64a2f35756b1e15e839642a26412..5e5948fcc6a5316046045a31f18fb193cbfb91da 100644 (file)
@@ -167,6 +167,8 @@ public class IssueJsonParserTest {
     assertThat(component.longName()).isEqualTo("org.struts.Action");
     assertThat(component.subProjectId()).isEqualTo(2L);
     assertThat(component.projectId()).isEqualTo(1L);
+
+    assertThat(issues.componentById(10).key()).isEqualTo("struts:Action.java");
   }
 
   @Test