test 123
[mir.git] / source / org / codecoop / mir / core / model / Category.java
1 /*
2  * $Id: Category.java,v 1.1 2004/11/06 16:20:48 idfx Exp $
3  *
4  * Copyright (C) 2001, 2002, 2003, 2004 The Mir-coders group
5  *
6  * This file is part of Mir.
7  *
8  * Mir is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Mir is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Mir; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  * In addition, as a special exception, The Mir-coders gives permission to link
23  * the code of this program with  any library licensed under the Apache Software License,
24  * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
25  * (or with modified versions of the above that use the same license as the above),
26  * and distribute linked combinations including the two.  You must obey the
27  * GNU General Public License in all respects for all of the code used other than
28  * the above mentioned libraries.  If you modify this file, you may extend this
29  * exception to your version of the file, but you are not obligated to do so.
30  * If you do not wish to do so, delete this exception statement from your version.
31  */
32 package org.codecoop.mir.core.model;
33
34 import java.io.Serializable;
35 import java.util.HashSet;
36 import java.util.Set;
37
38 import org.apache.commons.lang.builder.ToStringBuilder;
39
40 /**
41  * Category
42  * 
43  * @author idefix
44  */
45 public class Category implements Serializable {
46
47   /** identifier field */
48   private Integer id;
49
50   /** persistent field */
51   private String title;
52
53   /** nullable persistent field */
54   private String description;
55
56   /** persistent field */
57   private String filename;
58
59   /** nullable persistent field */
60   private CategoryType categoryType;
61
62   /** nullable persistent field */
63   private Category parentCategory;
64
65   /** persistent field */
66   private Set childCategories;
67
68   /** persistent field */
69   private Set articles;
70
71   private int hashCode;
72
73   /** default constructor */
74   public Category() {
75   }
76
77   public Integer getId() {
78     return this.id;
79   }
80
81   public void setId(Integer id) {
82     this.id = id;
83   }
84
85   public String getTitle() {
86     return this.title;
87   }
88
89   public void setTitle(String title) {
90     this.title = title;
91   }
92
93   public String getDescription() {
94     return this.description;
95   }
96
97   public void setDescription(String description) {
98     this.description = description;
99   }
100
101   public String getFilename() {
102     return this.filename;
103   }
104
105   public void setFilename(String filename) {
106     this.filename = filename;
107   }
108
109   public org.codecoop.mir.core.model.CategoryType getCategoryType() {
110     return this.categoryType;
111   }
112
113   public void setCategoryType(
114       org.codecoop.mir.core.model.CategoryType categoryType) {
115     this.categoryType = categoryType;
116   }
117
118   public Category getParentCategory() {
119     return this.parentCategory;
120   }
121
122   public void setParentCategory(Category parentCategory) {
123     this.parentCategory = parentCategory;
124   }
125   
126   public void addChildCategory(Category category){
127     if(childCategories == null){
128       childCategories = new HashSet();
129     }
130     childCategories.add(category);
131   }
132   
133   public Set getChildCategories() {
134     return this.childCategories;
135   }
136
137   public void setChildCategories(Set childTopics) {
138     this.childCategories = childTopics;
139   }
140
141   public Set getArticles() {
142     return this.articles;
143   }
144
145   public void setArticles(Set articles) {
146     this.articles = articles;
147   }
148   
149   public void addArticle(Article article){
150     if(articles == null){
151       articles = new HashSet();
152     }
153     articles.add(article);
154   }
155
156   public boolean equals(Object obj) {
157     if (null == obj) {
158       return false;
159     }
160     if (!(obj instanceof Category)) {
161       return false;
162     } else {
163       Category mObj = (Category) obj;
164       if (null == this.getId() || null == mObj.getId()) {
165         return false;
166       } else {
167         return (this.getId().equals(mObj.getId()));
168       }
169     }
170   }
171   
172   public int hashCode() {
173     if (Integer.MIN_VALUE == this.hashCode) {
174       if (null == this.getId()){
175         return super.hashCode();
176       } else {
177         String hashStr = this.getClass().getName() + ":"
178             + this.getId().hashCode();
179         this.hashCode = hashStr.hashCode();
180       }
181     }
182     return this.hashCode;
183   }
184
185   public String toString() {
186     return new ToStringBuilder(this).append("id", getId()).toString();
187   }
188 }