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.base.Paging;
023import org.sonar.wsclient.component.Component;
024import org.sonar.wsclient.issue.ActionPlan;
025import org.sonar.wsclient.issue.Issue;
026import org.sonar.wsclient.issue.Issues;
027import org.sonar.wsclient.rule.Rule;
028import org.sonar.wsclient.user.User;
029
030import javax.annotation.CheckForNull;
031import javax.annotation.Nullable;
032
033import java.util.*;
034
035/**
036 * @since 3.6
037 */
038public 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<String, Component> componentsByKey = new HashMap<String, Component>();
044  private final Map<String, Component> projectsByKey = new HashMap<String, Component>();
045  private final Map<String, ActionPlan> actionPlansByKey = new HashMap<String, ActionPlan>();
046  private Paging paging;
047  private Boolean maxResultsReached;
048
049  public List<Issue> list() {
050    return list;
051  }
052
053  public int size() {
054    return list.size();
055  }
056
057  public Collection<Rule> rules() {
058    return rulesByKey.values();
059  }
060
061  public Rule rule(Issue issue) {
062    return rulesByKey.get(issue.ruleKey());
063  }
064
065  public Collection<User> users() {
066    return usersByKey.values();
067  }
068
069  @CheckForNull
070  public User user(String login) {
071    return usersByKey.get(login);
072  }
073
074  public Collection<Component> components() {
075    return componentsByKey.values();
076  }
077
078  @CheckForNull
079  public Component component(Issue issue) {
080    return componentsByKey.get(issue.componentKey());
081  }
082
083  public Collection<Component> projects() {
084    return projectsByKey.values();
085  }
086
087  @CheckForNull
088  public Component project(Issue issue) {
089    return projectsByKey.get(issue.projectKey());
090  }
091
092  public Collection<ActionPlan> actionPlans() {
093    return actionPlansByKey.values();
094  }
095
096  @CheckForNull
097  public ActionPlan actionPlans(Issue issue) {
098    return actionPlansByKey.get(issue.actionPlan());
099  }
100
101  public Paging paging() {
102    return paging;
103  }
104
105  @Nullable
106  public Boolean maxResultsReached() {
107    return maxResultsReached;
108  }
109
110  DefaultIssues add(Issue issue) {
111    list.add(issue);
112    return this;
113  }
114
115  DefaultIssues add(Rule rule) {
116    rulesByKey.put(rule.key(), rule);
117    return this;
118  }
119
120  DefaultIssues add(User user) {
121    usersByKey.put(user.login(), user);
122    return this;
123  }
124
125  DefaultIssues add(ActionPlan actionPlan) {
126    actionPlansByKey.put(actionPlan.key(), actionPlan);
127    return this;
128  }
129
130  DefaultIssues addComponent(Component c) {
131    componentsByKey.put(c.key(), c);
132    return this;
133  }
134
135  DefaultIssues addProject(Component c) {
136    projectsByKey.put(c.key(), c);
137    return this;
138  }
139
140  DefaultIssues setPaging(Paging paging) {
141    this.paging = paging;
142    return this;
143  }
144
145  DefaultIssues setMaxResultsReached(@Nullable Boolean maxResultsReached) {
146    this.maxResultsReached = maxResultsReached;
147    return this;
148  }
149}