2 * $Id: Category.java,v 1.1 2004/11/06 16:20:48 idfx Exp $
4 * Copyright (C) 2001, 2002, 2003, 2004 The Mir-coders group
6 * This file is part of Mir.
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.
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.
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
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.
32 package org.codecoop.mir.core.model;
34 import java.io.Serializable;
35 import java.util.HashSet;
38 import org.apache.commons.lang.builder.ToStringBuilder;
45 public class Category implements Serializable {
47 /** identifier field */
50 /** persistent field */
53 /** nullable persistent field */
54 private String description;
56 /** persistent field */
57 private String filename;
59 /** nullable persistent field */
60 private CategoryType categoryType;
62 /** nullable persistent field */
63 private Category parentCategory;
65 /** persistent field */
66 private Set childCategories;
68 /** persistent field */
73 /** default constructor */
77 public Integer getId() {
81 public void setId(Integer id) {
85 public String getTitle() {
89 public void setTitle(String title) {
93 public String getDescription() {
94 return this.description;
97 public void setDescription(String description) {
98 this.description = description;
101 public String getFilename() {
102 return this.filename;
105 public void setFilename(String filename) {
106 this.filename = filename;
109 public org.codecoop.mir.core.model.CategoryType getCategoryType() {
110 return this.categoryType;
113 public void setCategoryType(
114 org.codecoop.mir.core.model.CategoryType categoryType) {
115 this.categoryType = categoryType;
118 public Category getParentCategory() {
119 return this.parentCategory;
122 public void setParentCategory(Category parentCategory) {
123 this.parentCategory = parentCategory;
126 public void addChildCategory(Category category){
127 if(childCategories == null){
128 childCategories = new HashSet();
130 childCategories.add(category);
133 public Set getChildCategories() {
134 return this.childCategories;
137 public void setChildCategories(Set childTopics) {
138 this.childCategories = childTopics;
141 public Set getArticles() {
142 return this.articles;
145 public void setArticles(Set articles) {
146 this.articles = articles;
149 public void addArticle(Article article){
150 if(articles == null){
151 articles = new HashSet();
153 articles.add(article);
156 public boolean equals(Object obj) {
160 if (!(obj instanceof Category)) {
163 Category mObj = (Category) obj;
164 if (null == this.getId() || null == mObj.getId()) {
167 return (this.getId().equals(mObj.getId()));
172 public int hashCode() {
173 if (Integer.MIN_VALUE == this.hashCode) {
174 if (null == this.getId()){
175 return super.hashCode();
177 String hashStr = this.getClass().getName() + ":"
178 + this.getId().hashCode();
179 this.hashCode = hashStr.hashCode();
182 return this.hashCode;
185 public String toString() {
186 return new ToStringBuilder(this).append("id", getId()).toString();