KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > impl > basic > Category


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: Category.java,v 1.9 2003/06/25 22:52:42 niko_schmuck Exp $
28

29 package de.nava.informa.impl.basic;
30
31 import java.util.Collection JavaDoc;
32 import java.util.ArrayList JavaDoc;
33
34 import de.nava.informa.core.CategoryIF;
35
36 /**
37  * In-Memory implementation of the CategoryIF interface.
38  *
39  * @author Niko Schmuck (niko@nava.de)
40  */

41 public class Category implements CategoryIF, java.io.Serializable JavaDoc {
42
43   private long id;
44   private String JavaDoc title;
45   private CategoryIF parent;
46   private Collection JavaDoc children;
47
48   public Category() {
49     this("[Unnamed Category]");
50   }
51   
52   public Category(String JavaDoc title) {
53     this(null, title);
54   }
55
56   public Category(CategoryIF parent, String JavaDoc title) {
57     this.id = IdGenerator.getInstance().getId();
58     this.title = title;
59     this.parent = parent;
60     this.children = new ArrayList JavaDoc();
61   }
62   
63   // --------------------------------------------------------------
64
// implementation of CategoryIF interface
65
// --------------------------------------------------------------
66

67   public long getId() {
68     return id;
69   }
70
71   public void setId(long id) {
72     this.id = id;
73   }
74
75   public String JavaDoc getTitle() {
76     return title;
77   }
78
79   public void setTitle(String JavaDoc title) {
80     this.title = title;
81   }
82
83   public CategoryIF getParent() {
84     return parent;
85   }
86
87   public void setParent(CategoryIF parent) {
88     this.parent = parent;
89   }
90
91   public Collection JavaDoc getChildren() {
92     return children;
93   }
94   
95   public void addChild(CategoryIF child) {
96     children.add(child);
97     child.setParent(this);
98   }
99   
100   public void removeChild(CategoryIF child) {
101     children.remove(child);
102   }
103   
104   // --------------------------------------------------------------
105
// overwrite default method implementation from Object
106
// --------------------------------------------------------------
107

108   public boolean equals(Object JavaDoc obj) {
109     if (!(obj instanceof CategoryIF)) {
110       return false;
111     }
112     CategoryIF cmp = (CategoryIF) obj;
113
114     return cmp.getTitle().equals(title)
115       && (cmp.getId() == id);
116   }
117   
118   public int hashCode() {
119     return title.hashCode() + new Long JavaDoc(id).hashCode();
120   }
121   
122   public String JavaDoc toString() {
123     return "[Category (" + id + "): " + title + "]";
124   }
125   
126 }
127
Popular Tags