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> 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 componentsById.values(); 076 } 077 078 @CheckForNull 079 public Component component(Issue issue) { 080 return componentsById.get(issue.componentId()); 081 } 082 083 @CheckForNull 084 public Component componentById(long id) { 085 return componentsById.get(id); 086 } 087 088 public Collection<Component> projects() { 089 return projectsByKey.values(); 090 } 091 092 @CheckForNull 093 public Component project(Issue issue) { 094 return projectsByKey.get(issue.projectKey()); 095 } 096 097 public Collection<ActionPlan> actionPlans() { 098 return actionPlansByKey.values(); 099 } 100 101 @CheckForNull 102 public ActionPlan actionPlans(Issue issue) { 103 return actionPlansByKey.get(issue.actionPlan()); 104 } 105 106 public Paging paging() { 107 return paging; 108 } 109 110 @Nullable 111 public Boolean maxResultsReached() { 112 return maxResultsReached; 113 } 114 115 DefaultIssues add(Issue issue) { 116 list.add(issue); 117 return this; 118 } 119 120 DefaultIssues add(Rule rule) { 121 rulesByKey.put(rule.key(), rule); 122 return this; 123 } 124 125 DefaultIssues add(User user) { 126 usersByKey.put(user.login(), user); 127 return this; 128 } 129 130 DefaultIssues add(ActionPlan actionPlan) { 131 actionPlansByKey.put(actionPlan.key(), actionPlan); 132 return this; 133 } 134 135 DefaultIssues addComponent(Component c) { 136 componentsById.put(c.id(), c); 137 return this; 138 } 139 140 DefaultIssues addProject(Component c) { 141 projectsByKey.put(c.key(), c); 142 return this; 143 } 144 145 DefaultIssues setPaging(Paging paging) { 146 this.paging = paging; 147 return this; 148 } 149 150 DefaultIssues setMaxResultsReached(@Nullable Boolean maxResultsReached) { 151 this.maxResultsReached = maxResultsReached; 152 return this; 153 } 154 }