001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.wsclient.issue.internal; 021 022import org.sonar.wsclient.component.Component; 023import org.sonar.wsclient.issue.ActionPlan; 024import org.sonar.wsclient.issue.Issue; 025import org.sonar.wsclient.issue.Issues; 026import org.sonar.wsclient.base.Paging; 027import org.sonar.wsclient.rule.Rule; 028import org.sonar.wsclient.user.User; 029 030import javax.annotation.CheckForNull; 031import java.util.*; 032 033/** 034 * @since 3.6 035 */ 036public class DefaultIssues implements Issues { 037 038 private final List<Issue> list = new ArrayList<Issue>(); 039 private final Map<String, Rule> rulesByKey = new HashMap<String, Rule>(); 040 private final Map<String, User> usersByKey = new HashMap<String, User>(); 041 private final Map<String, Component> componentsByKey = new HashMap<String, Component>(); 042 private final Map<String, Component> projectsByKey = new HashMap<String, Component>(); 043 private final Map<String, ActionPlan> actionPlansByKey = new HashMap<String, ActionPlan>(); 044 private Paging paging; 045 private Boolean maxResultsReached; 046 047 public List<Issue> list() { 048 return list; 049 } 050 051 public int size() { 052 return list.size(); 053 } 054 055 public Collection<Rule> rules() { 056 return rulesByKey.values(); 057 } 058 059 public Rule rule(Issue issue) { 060 return rulesByKey.get(issue.ruleKey()); 061 } 062 063 public Collection<User> users() { 064 return usersByKey.values(); 065 } 066 067 @CheckForNull 068 public User user(String login) { 069 return usersByKey.get(login); 070 } 071 072 public Collection<Component> components() { 073 return componentsByKey.values(); 074 } 075 076 @CheckForNull 077 public Component component(Issue issue) { 078 return componentsByKey.get(issue.componentKey()); 079 } 080 081 public Collection<Component> projects() { 082 return projectsByKey.values(); 083 } 084 085 @CheckForNull 086 public Component project(Issue issue) { 087 return projectsByKey.get(issue.projectKey()); 088 } 089 090 public Collection<ActionPlan> actionPlans() { 091 return actionPlansByKey.values(); 092 } 093 094 @CheckForNull 095 public ActionPlan actionPlans(Issue issue) { 096 return actionPlansByKey.get(issue.actionPlan()); 097 } 098 099 public Paging paging() { 100 return paging; 101 } 102 103 public Boolean maxResultsReached() { 104 return maxResultsReached; 105 } 106 107 DefaultIssues add(Issue issue) { 108 list.add(issue); 109 return this; 110 } 111 112 DefaultIssues add(Rule rule) { 113 rulesByKey.put(rule.key(), rule); 114 return this; 115 } 116 117 DefaultIssues add(User user) { 118 usersByKey.put(user.login(), user); 119 return this; 120 } 121 122 DefaultIssues add(ActionPlan actionPlan) { 123 actionPlansByKey.put(actionPlan.key(), actionPlan); 124 return this; 125 } 126 127 DefaultIssues addComponent(Component c) { 128 componentsByKey.put(c.key(), c); 129 return this; 130 } 131 132 DefaultIssues addProject(Component c) { 133 projectsByKey.put(c.key(), c); 134 return this; 135 } 136 137 DefaultIssues setPaging(Paging paging) { 138 this.paging = paging; 139 return this; 140 } 141 142 DefaultIssues setMaxResultsReached(Boolean maxResultsReached) { 143 this.maxResultsReached = maxResultsReached; 144 return this; 145 } 146}