001/* 002 * SonarQube 003 * Copyright (C) 2009-2018 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 java.util.Collections; 023import java.util.HashMap; 024import java.util.Map; 025import javax.annotation.concurrent.Immutable; 026import org.sonar.api.batch.rule.ActiveRule; 027import org.sonar.api.rule.RuleKey; 028 029@Immutable 030public class DefaultActiveRule implements ActiveRule { 031 private final RuleKey ruleKey; 032 private final String severity; 033 private final String internalKey; 034 private final String language; 035 private final String templateRuleKey; 036 private final Map<String, String> params; 037 private final long createdAt; 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 = Collections.unmodifiableMap(new HashMap<>(newActiveRule.params)); 045 this.language = newActiveRule.language; 046 this.createdAt = newActiveRule.createdAt; 047 } 048 049 @Override 050 public RuleKey ruleKey() { 051 return ruleKey; 052 } 053 054 @Override 055 public String severity() { 056 return severity; 057 } 058 059 @Override 060 public String language() { 061 return language; 062 } 063 064 @Override 065 public String param(String key) { 066 return params.get(key); 067 } 068 069 @Override 070 public Map<String, String> params() { 071 // already immutable 072 return params; 073 } 074 075 @Override 076 public String internalKey() { 077 return internalKey; 078 } 079 080 @Override 081 public String templateRuleKey() { 082 return templateRuleKey; 083 } 084 085 public long createdAt() { 086 return createdAt; 087 } 088}