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 public List<Issue> list() { 051 return list; 052 } 053 054 public int size() { 055 return list.size(); 056 } 057 058 public Collection<Rule> rules() { 059 return rulesByKey.values(); 060 } 061 062 public Rule rule(Issue issue) { 063 return rulesByKey.get(issue.ruleKey()); 064 } 065 066 public Collection<User> users() { 067 return usersByKey.values(); 068 } 069 070 @CheckForNull 071 public User user(String login) { 072 return usersByKey.get(login); 073 } 074 075 public Collection<Component> components() { 076 return componentsByKey.values(); 077 } 078 079 @CheckForNull 080 public Component component(Issue issue) { 081 return componentsByKey.get(issue.componentKey()); 082 } 083 084 @CheckForNull 085 public Component componentById(long id) { 086 return componentsById.get(id); 087 } 088 089 @CheckForNull 090 public Component componentByKey(String key) { 091 return componentsByKey.get(key); 092 } 093 094 public Collection<Component> projects() { 095 return projectsByKey.values(); 096 } 097 098 @CheckForNull 099 public Component project(Issue issue) { 100 return projectsByKey.get(issue.projectKey()); 101 } 102 103 public Collection<ActionPlan> actionPlans() { 104 return actionPlansByKey.values(); 105 } 106 107 @CheckForNull 108 public ActionPlan actionPlans(Issue issue) { 109 return actionPlansByKey.get(issue.actionPlan()); 110 } 111 112 public Paging paging() { 113 return paging; 114 } 115 116 @Nullable 117 public Boolean maxResultsReached() { 118 return maxResultsReached; 119 } 120 121 DefaultIssues add(Issue issue) { 122 list.add(issue); 123 return this; 124 } 125 126 DefaultIssues add(Rule rule) { 127 rulesByKey.put(rule.key(), rule); 128 return this; 129 } 130 131 DefaultIssues add(User user) { 132 usersByKey.put(user.login(), user); 133 return this; 134 } 135 136 DefaultIssues add(ActionPlan actionPlan) { 137 actionPlansByKey.put(actionPlan.key(), actionPlan); 138 return this; 139 } 140 141 DefaultIssues addComponent(Component c) { 142 componentsById.put(c.id(), c); 143 componentsByKey.put(c.key(), c); 144 return this; 145 } 146 147 DefaultIssues addProject(Component c) { 148 projectsByKey.put(c.key(), c); 149 return this; 150 } 151 152 DefaultIssues setPaging(Paging paging) { 153 this.paging = paging; 154 return this; 155 } 156 157 DefaultIssues setMaxResultsReached(@Nullable Boolean maxResultsReached) { 158 this.maxResultsReached = maxResultsReached; 159 return this; 160 } 161 }