001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2009 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar 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 * Sonar 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 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.api.checks.profiles; 021 022 import org.sonar.api.BatchExtension; 023 import org.sonar.api.ServerExtension; 024 025 import java.util.ArrayList; 026 import java.util.Collection; 027 import java.util.List; 028 029 /** 030 * @since 2.1 (experimental) 031 * @deprecated since 2.3 032 */ 033 @Deprecated 034 public class CheckProfile implements BatchExtension, ServerExtension { 035 036 private String name; 037 private String language; 038 private List<Check> checks = new ArrayList<Check>(); 039 040 public CheckProfile(String name, String language) { 041 if (name == null) { 042 throw new IllegalArgumentException("Name can not be null"); 043 } 044 if (language == null) { 045 throw new IllegalArgumentException("Language can not be null"); 046 } 047 this.name = name; 048 this.language = language; 049 } 050 051 public String getName() { 052 return name; 053 } 054 055 public String getLanguage() { 056 return language; 057 } 058 059 public List<Check> getChecks() { 060 return checks; 061 } 062 063 public List<Check> getChecks(String repositoryKey) { 064 List<Check> result = new ArrayList<Check>(); 065 for (Check check : getChecks()) { 066 if (check.getRepositoryKey().equals(repositoryKey)) { 067 result.add(check); 068 } 069 } 070 return result; 071 } 072 073 public List<Check> getChecks(String repositoryKey, String templateKey) { 074 List<Check> result = new ArrayList<Check>(); 075 List<Check> repoChecks = getChecks(repositoryKey); 076 for (Check repoCheck : repoChecks) { 077 if (repoCheck.getTemplateKey().equals(templateKey)) { 078 result.add(repoCheck); 079 } 080 } 081 return result; 082 } 083 084 /** 085 * We assume there is only one check for this template 086 */ 087 public Check getCheck(String repositoryKey, String templateKey) { 088 List<Check> repoChecks = getChecks(repositoryKey); 089 for (Check repoCheck : repoChecks) { 090 if (repoCheck.getTemplateKey().equals(templateKey)) { 091 return repoCheck; 092 } 093 } 094 return null; 095 } 096 097 public void addCheck(Check check) { 098 checks.add(check); 099 } 100 101 public void setChecks(Collection<Check> list) { 102 checks.clear(); 103 checks.addAll(list); 104 } 105 106 @Override 107 public boolean equals(Object o) { 108 if (this == o) { 109 return true; 110 } 111 if (o == null || getClass() != o.getClass()) { 112 return false; 113 } 114 115 CheckProfile profile = (CheckProfile) o; 116 if (!language.equals(profile.language)) { 117 return false; 118 } 119 if (!name.equals(profile.name)) { 120 return false; 121 } 122 return true; 123 } 124 125 @Override 126 public int hashCode() { 127 int result = name.hashCode(); 128 result = 31 * result + language.hashCode(); 129 return result; 130 } 131 132 @Override 133 public String toString() { 134 return name; 135 } 136 }