001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2009 SonarSource SA
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.rules;
021    
022    import org.apache.commons.lang.builder.EqualsBuilder;
023    import org.apache.commons.lang.builder.HashCodeBuilder;
024    import org.apache.commons.lang.builder.ReflectionToStringBuilder;
025    import org.sonar.api.resources.Resource;
026    
027    public class Violation {
028    
029      private Resource resource;
030      private Rule rule;
031      private String message;
032      private RulePriority priority;
033      private Integer lineId;
034    
035      public Violation(Rule rule) {
036        this.rule = rule;
037      }
038    
039      public Violation(Rule rule, Resource resource) {
040        this.resource = resource;
041        this.rule = rule;
042      }
043    
044      public Resource getResource() {
045        return resource;
046      }
047    
048      public Violation setResource(Resource resource) {
049        this.resource = resource;
050        return this;
051      }
052    
053      public Rule getRule() {
054        return rule;
055      }
056    
057      public Violation setRule(Rule rule) {
058        this.rule = rule;
059        return this;
060      }
061    
062      public String getMessage() {
063        return message;
064      }
065    
066      public Violation setMessage(String message) {
067        this.message = message;
068        return this;
069      }
070    
071      public Integer getLineId() {
072        return lineId;
073      }
074    
075      public Violation setLineId(Integer lineId) {
076        this.lineId = lineId;
077        return this;
078      }
079    
080      public RulePriority getPriority() {
081        return priority;
082      }
083    
084      public Violation setPriority(RulePriority priority) {
085        this.priority = priority;
086        return this;
087      }
088    
089      @Override
090      public boolean equals(Object obj) {
091        if (!(obj instanceof Violation)) {
092          return false;
093        }
094        if (this == obj) {
095          return true;
096        }
097        Violation other = (Violation) obj;
098        return new EqualsBuilder()
099            .append(rule, other.getRule())
100            .append(resource, other.getResource())
101            .isEquals();
102      }
103    
104      @Override
105      public int hashCode() {
106        return new HashCodeBuilder(17, 37)
107            .append(getRule())
108            .append(getResource())
109            .toHashCode();
110      }
111    
112      @Override
113      public String toString() {
114        return ReflectionToStringBuilder.toString(this);
115      }
116    }