001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 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 */
020 package org.sonar.wsclient.issue.internal;
021
022 import org.sonar.wsclient.base.Paging;
023 import org.sonar.wsclient.component.Component;
024 import org.sonar.wsclient.issue.ActionPlan;
025 import org.sonar.wsclient.issue.Issue;
026 import org.sonar.wsclient.issue.Issues;
027 import org.sonar.wsclient.rule.Rule;
028 import org.sonar.wsclient.user.User;
029
030 import javax.annotation.CheckForNull;
031 import javax.annotation.Nullable;
032
033 import java.util.*;
034
035 /**
036 * @since 3.6
037 */
038 public class DefaultIssues implements Issues {
039
040 private final List<Issue> list = new ArrayList<Issue>();
041 private final Map<String, Rule> rulesByKey = new HashMap<String, Rule>();
042 private final Map<String, User> usersByKey = new HashMap<String, User>();
043 private final Map<Long, Component> componentsById = new HashMap<Long, Component>();
044 private final Map<String, Component> componentsByKey = new HashMap<String, Component>();
045 private final Map<String, Component> projectsByKey = new HashMap<String, Component>();
046 private final Map<String, ActionPlan> actionPlansByKey = new HashMap<String, ActionPlan>();
047 private Paging paging;
048 private Boolean maxResultsReached;
049
050 @Override
051 public List<Issue> list() {
052 return list;
053 }
054
055 @Override
056 public int size() {
057 return list.size();
058 }
059
060 @Override
061 public Collection<Rule> rules() {
062 return rulesByKey.values();
063 }
064
065 @Override
066 public Rule rule(Issue issue) {
067 return rulesByKey.get(issue.ruleKey());
068 }
069
070 @Override
071 public Collection<User> users() {
072 return usersByKey.values();
073 }
074
075 @Override
076 @CheckForNull
077 public User user(String login) {
078 return usersByKey.get(login);
079 }
080
081 @Override
082 public Collection<Component> components() {
083 return componentsByKey.values();
084 }
085
086 @Override
087 @CheckForNull
088 public Component component(Issue issue) {
089 return componentsByKey.get(issue.componentKey());
090 }
091
092 @Override
093 @CheckForNull
094 public Component componentById(long id) {
095 return componentsById.get(id);
096 }
097
098 @Override
099 @CheckForNull
100 public Component componentByKey(String key) {
101 return componentsByKey.get(key);
102 }
103
104 @Override
105 public Collection<Component> projects() {
106 return projectsByKey.values();
107 }
108
109 @Override
110 @CheckForNull
111 public Component project(Issue issue) {
112 return projectsByKey.get(issue.projectKey());
113 }
114
115 @Override
116 public Collection<ActionPlan> actionPlans() {
117 return actionPlansByKey.values();
118 }
119
120 @Override
121 @CheckForNull
122 public ActionPlan actionPlans(Issue issue) {
123 return actionPlansByKey.get(issue.actionPlan());
124 }
125
126 @Override
127 public Paging paging() {
128 return paging;
129 }
130
131 @Override
132 @Nullable
133 public Boolean maxResultsReached() {
134 return maxResultsReached;
135 }
136
137 DefaultIssues add(Issue issue) {
138 list.add(issue);
139 return this;
140 }
141
142 DefaultIssues add(Rule rule) {
143 rulesByKey.put(rule.key(), rule);
144 return this;
145 }
146
147 DefaultIssues add(User user) {
148 usersByKey.put(user.login(), user);
149 return this;
150 }
151
152 DefaultIssues add(ActionPlan actionPlan) {
153 actionPlansByKey.put(actionPlan.key(), actionPlan);
154 return this;
155 }
156
157 DefaultIssues addComponent(Component c) {
158 componentsById.put(c.id(), c);
159 componentsByKey.put(c.key(), c);
160 return this;
161 }
162
163 DefaultIssues addProject(Component c) {
164 projectsByKey.put(c.key(), c);
165 return this;
166 }
167
168 DefaultIssues setPaging(Paging paging) {
169 this.paging = paging;
170 return this;
171 }
172
173 DefaultIssues setMaxResultsReached(@Nullable Boolean maxResultsReached) {
174 this.maxResultsReached = maxResultsReached;
175 return this;
176 }
177 }