001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program 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 * This program 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.api.batch.rule.internal; 021 022import com.google.common.collect.ImmutableMap; 023import org.sonar.api.batch.rule.ActiveRule; 024import org.sonar.api.rule.RuleKey; 025 026import javax.annotation.concurrent.Immutable; 027 028import java.util.Map; 029 030@Immutable 031public class DefaultActiveRule implements ActiveRule { 032 private final RuleKey ruleKey; 033 private final String severity; 034 private final String internalKey; 035 private final String language; 036 private final String templateRuleKey; 037 private final Map<String, String> params; 038 039 DefaultActiveRule(NewActiveRule newActiveRule) { 040 this.severity = newActiveRule.severity; 041 this.internalKey = newActiveRule.internalKey; 042 this.templateRuleKey = newActiveRule.templateRuleKey; 043 this.ruleKey = newActiveRule.ruleKey; 044 this.params = ImmutableMap.copyOf(newActiveRule.params); 045 this.language = newActiveRule.language; 046 } 047 048 @Override 049 public RuleKey ruleKey() { 050 return ruleKey; 051 } 052 053 @Override 054 public String severity() { 055 return severity; 056 } 057 058 @Override 059 public String language() { 060 return language; 061 } 062 063 @Override 064 public String param(String key) { 065 return params.get(key); 066 } 067 068 @Override 069 public Map<String, String> params() { 070 // already immutable 071 return params; 072 } 073 074 @Override 075 public String internalKey() { 076 return internalKey; 077 } 078 079 @Override 080 public String templateRuleKey() { 081 return templateRuleKey; 082 } 083}