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 */
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 name;
034  private final String severity, internalKey, language, templateRuleKey;
035  private final Map<String, String> params;
036
037  DefaultActiveRule(NewActiveRule newActiveRule) {
038    this.severity = newActiveRule.severity;
039    this.name = newActiveRule.name;
040    this.internalKey = newActiveRule.internalKey;
041    this.templateRuleKey = newActiveRule.templateRuleKey;
042    this.ruleKey = newActiveRule.ruleKey;
043    this.params = ImmutableMap.copyOf(newActiveRule.params);
044    this.language = newActiveRule.language;
045  }
046
047  @Override
048  public RuleKey ruleKey() {
049    return ruleKey;
050  }
051
052  public String name() {
053    return name;
054  }
055
056  @Override
057  public String severity() {
058    return severity;
059  }
060
061  @Override
062  public String language() {
063    return language;
064  }
065
066  @Override
067  public String param(String key) {
068    return params.get(key);
069  }
070
071  @Override
072  public Map<String, String> params() {
073    // already immutable
074    return params;
075  }
076
077  @Override
078  public String internalKey() {
079    return internalKey;
080  }
081
082  @Override
083  public String templateRuleKey() {
084    return templateRuleKey;
085  }
086}