001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 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.measures; 021 022 import org.apache.commons.lang.builder.EqualsBuilder; 023 import org.apache.commons.lang.builder.HashCodeBuilder; 024 import org.apache.commons.lang.builder.ToStringBuilder; 025 import org.sonar.api.rules.Rule; 026 import org.sonar.api.rules.RulePriority; 027 028 /** 029 * @since 1.10 030 */ 031 public class RuleMeasure extends Measure { 032 033 private Rule rule; 034 private RulePriority rulePriority; 035 036 /** 037 * This constructor is for internal use only. Please use static methods createForXXX(). 038 */ 039 public RuleMeasure(Metric metric, Rule rule, RulePriority rulePriority, Integer ruleCategory) { 040 super(metric); 041 this.rule = rule; 042 this.rulePriority = rulePriority; 043 } 044 045 public Rule getRule() { 046 return rule; 047 } 048 049 public void setRule(Rule rule) { 050 this.rule = rule; 051 } 052 053 public RulePriority getRulePriority() { 054 return rulePriority; 055 } 056 057 public void setRulePriority(RulePriority rulePriority) { 058 this.rulePriority = rulePriority; 059 } 060 061 /** 062 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 063 */ 064 @Deprecated 065 public Integer getRuleCategory() { 066 return null; 067 } 068 069 /** 070 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 071 */ 072 @Deprecated 073 public void setRuleCategory(Integer ruleCategory) { 074 075 } 076 077 @Override 078 public boolean equals(Object obj) { 079 if (obj == null) { 080 return false; 081 } 082 if (!(obj.getClass().equals(RuleMeasure.class))) {//NOSONAR should be refactored but kept in the current state 083 // for the moment. 084 return false; 085 } 086 if (this == obj) { 087 return true; 088 } 089 RuleMeasure other = (RuleMeasure) obj; 090 return new EqualsBuilder() 091 .append(getMetric(), other.getMetric()) 092 .append(rule, other.rule) 093 .isEquals(); 094 } 095 096 @Override 097 public RuleMeasure setValue(Double v) { 098 return (RuleMeasure) super.setValue(v); 099 } 100 101 @Override 102 public int hashCode() { 103 return new HashCodeBuilder(17, 37). 104 append(getMetric()). 105 append(rule). 106 toHashCode(); 107 } 108 109 @Override 110 public String toString() { 111 return new ToStringBuilder(this). 112 append("id", getId()). 113 append("metric", metric). 114 append("rule", rule). 115 append("value", value). 116 append("data", data). 117 append("description", description). 118 append("alertStatus", alertStatus). 119 append("alertText", alertText). 120 append("tendency", tendency). 121 append("severity", rulePriority). 122 toString(); 123 } 124 125 public static RuleMeasure createForRule(Metric metric, Rule rule, Double value) { 126 return new RuleMeasure(metric, rule, null, null).setValue(value); 127 } 128 129 public static RuleMeasure createForPriority(Metric metric, RulePriority priority, Double value) { 130 return new RuleMeasure(metric, null, priority, null).setValue(value); 131 } 132 133 /** 134 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 135 */ 136 @Deprecated 137 public static RuleMeasure createForCategory(Metric metric, Integer category, Double value) { 138 return (RuleMeasure) new RuleMeasure(metric, null, null, category).setValue(value); 139 } 140 }