001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info 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 java.util.Map;
024import javax.annotation.concurrent.Immutable;
025import org.sonar.api.batch.rule.ActiveRule;
026import org.sonar.api.rule.RuleKey;
027
028@Immutable
029public class DefaultActiveRule implements ActiveRule {
030  private final RuleKey ruleKey;
031  private final String severity;
032  private final String internalKey;
033  private final String language;
034  private final String templateRuleKey;
035  private final Map<String, String> params;
036  private final long createdAt;
037
038  DefaultActiveRule(NewActiveRule newActiveRule) {
039    this.severity = newActiveRule.severity;
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    this.createdAt = newActiveRule.createdAt;
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
084  public long createdAt() {
085    return createdAt;
086  }
087}