diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-17 15:28:42 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-17 15:29:48 +0100 |
commit | 2ec12bf1b6ea57eaaa2f1feae0df1b2f3f702d3c (patch) | |
tree | b98ce17be026ece6d8255a9336e25e67ee710a30 /sonar-ws-client | |
parent | ac36bd23ad0dd1b312f28d6612f0f4a1b57fb41e (diff) | |
download | sonarqube-2ec12bf1b6ea57eaaa2f1feae0df1b2f3f702d3c.tar.gz sonarqube-2ec12bf1b6ea57eaaa2f1feae0df1b2f3f702d3c.zip |
Add Issues.componentById() helper
Diffstat (limited to 'sonar-ws-client')
3 files changed, 14 insertions, 4 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java index 7e6fc88e203..0b7de948226 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java @@ -51,6 +51,9 @@ public interface Issues { @CheckForNull Component component(Issue issue); + @CheckForNull + Component componentById(long id); + Collection<Component> projects(); @CheckForNull diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssues.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssues.java index e4693e370e4..2b76fa74634 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssues.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssues.java @@ -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; } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java index 2ea31630d82..5e5948fcc6a 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java @@ -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 |