View Javadoc

1   /*
2    * Sonar, entreprise quality control tool.
3    * Copyright (C) 2007-2008 Hortis-GRC SA
4    * mailto:be_agile HAT hortis DOT ch
5    *
6    * Sonar is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * Sonar is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with Sonar; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19   */
20  package ch.hortis.sonar.service;
21  
22  import ch.hortis.sonar.model.Metric;
23  import ch.hortis.sonar.model.ProjectMeasure;
24  import ch.hortis.sonar.model.Rule;
25  import org.apache.commons.lang.builder.EqualsBuilder;
26  import org.apache.commons.lang.builder.HashCodeBuilder;
27  
28  public class MeasureKey implements Cloneable {
29    protected Metric metric;
30    protected Integer rulesCategoryId;
31    protected Rule rule;
32  
33    public MeasureKey(Metric metric, Integer rulesCategoryId, Rule rule) {
34      this.metric = metric;
35      this.rulesCategoryId = rulesCategoryId;
36      this.rule = rule;
37    }
38  
39    public MeasureKey(Metric metric) {
40      this(metric, (Integer)null, null);
41    }
42  
43    public MeasureKey(ProjectMeasure measure) {
44      this(measure.getMetric(), measure.getRulesCategoryId(), measure.getRule());
45    }
46  
47    public boolean equals(Object obj) {
48      if (!(obj instanceof MeasureKey)) {
49        return false;
50      }
51      if (this == obj) {
52        return true;
53      }
54      MeasureKey other = (MeasureKey) obj;
55      return new EqualsBuilder().
56        append(metric, other.metric).
57        append(rulesCategoryId, other.rulesCategoryId).
58        append(rule, other.rule).
59        isEquals();
60    }
61  
62    public int hashCode() {
63      return new HashCodeBuilder(17, 37).
64        append(metric).
65        append(rulesCategoryId).
66        append(rule).
67        toHashCode();
68    }
69  
70    public Object clone() {
71      return new MeasureKey(this.metric, this.rulesCategoryId, this.rule);
72    }
73  
74  
75    public Metric getMetric() {
76      return metric;
77    }
78  
79    public MeasureKey setMetric(Metric metric) {
80      this.metric = metric;
81      return this;
82    }
83  
84    public Integer getRulesCategoryId() {
85      return rulesCategoryId;
86    }
87  
88    public MeasureKey setRulesCategoryId(Integer id) {
89      this.rulesCategoryId = id;
90      return this;
91    }
92  
93    public Rule getRule() {
94      return rule;
95    }
96  
97    public MeasureKey setRule(Rule rule) {
98      this.rule = rule;
99      return this;
100   }
101 
102 }