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.ToStringBuilder;
025    import org.hibernate.annotations.Cache;
026    import org.hibernate.annotations.CacheConcurrencyStrategy;
027    import org.hibernate.annotations.Immutable;
028    import org.sonar.api.database.BaseIdentifiable;
029    
030    import javax.persistence.Column;
031    import javax.persistence.Entity;
032    import javax.persistence.Table;
033    
034    /**
035     * A class to hold rules category
036     */
037    @Immutable
038    @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
039    @Entity
040    @Table(name = "rules_categories")
041    public class RulesCategory extends BaseIdentifiable {
042    
043      @Column(name = "name", updatable = false, nullable = false)
044      private String name;
045    
046      @Column(name = "description", updatable = false, nullable = true)
047      private String description;
048    
049      /**
050       * Creates a RuleCategory based on the category name
051       *
052       * @param name the category name
053       */
054      public RulesCategory(String name) {
055        this.name = name;
056      }
057    
058      /**
059       * Creates a category based on the category name and description
060       *
061       * @param name the category name
062       * @param description the category description
063       */
064      public RulesCategory(String name, String description) {
065        this.name = name;
066        this.description = description;
067      }
068    
069      /**
070       * Creates an empty category
071       */
072      public RulesCategory() {
073      }
074    
075      /**
076       * @return the category name
077       */
078      public String getName() {
079        return name;
080      }
081    
082      /**
083       * Sets the category name
084       *
085       * @param name the name
086       */
087      public void setName(String name) {
088        this.name = name;
089      }
090    
091      /**
092       * @return the category description
093       */
094      public String getDescription() {
095        return description;
096      }
097    
098      /**
099       * Sets the cay description
100       * @param description the description
101       */
102      public void setDescription(String description) {
103        this.description = description;
104      }
105    
106      @Override
107      public boolean equals(Object obj) {
108        if (!(obj instanceof RulesCategory)) {
109          return false;
110        }
111        if (this == obj) {
112          return true;
113        }
114        RulesCategory other = (RulesCategory) obj;
115        return new EqualsBuilder()
116            .append(name, other.getName()).isEquals();
117      }
118    
119      @Override
120      public int hashCode() {
121        return new HashCodeBuilder(17, 37)
122            .append(name)
123            .toHashCode();
124      }
125    
126      @Override
127      public String toString() {
128        return new ToStringBuilder(this)
129            .append("id", getId())
130            .append("name", name)
131            .append("desc", description)
132            .toString();
133      }
134    
135    }