KickJava   Java API By Example, From Geeks To Geeks.

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


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: ChannelGroup.java,v 1.9 2003/07/26 09:48:36 niko_schmuck Exp $
28

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

44 public class ChannelGroup implements ChannelGroupIF,
45                                      java.io.Serializable JavaDoc {
46
47   private long id;
48   private String JavaDoc title;
49   private Collection JavaDoc channels;
50   private ChannelGroupIF parent;
51   private List JavaDoc children;
52
53   public ChannelGroup() {
54     this("[Unknown title]");
55   }
56   
57   public ChannelGroup(String JavaDoc title) {
58     this(IdGenerator.getInstance().getId(), null, title);
59   }
60   
61   public ChannelGroup(long id, String JavaDoc title) {
62     this(id, null, title);
63   }
64   
65   public ChannelGroup(long id, ChannelGroupIF parent, String JavaDoc title) {
66     this.id = id;
67     this.title = title;
68     this.channels = new ArrayList JavaDoc();
69     this.parent = parent;
70     this.children = new ArrayList JavaDoc();
71   }
72
73   // --------------------------------------------------------------
74
// implementation of ChannelGroupIF interface
75
// --------------------------------------------------------------
76

77   public long getId() {
78     return id;
79   }
80
81   public void setId(long id) {
82     this.id = id;
83   }
84
85   public String JavaDoc getTitle() {
86     return title;
87   }
88
89   public void setTitle(String JavaDoc title) {
90     this.title = title;
91   }
92
93   public void add(ChannelIF channel) {
94     channels.add(channel);
95   }
96
97   public void remove(ChannelIF channel) {
98     channels.remove(channel);
99   }
100
101   public Collection JavaDoc getAll() {
102     return channels;
103   }
104
105   public ChannelIF getById(long id) {
106     Iterator JavaDoc it = channels.iterator();
107     while (it.hasNext()) {
108       ChannelIF channel = (ChannelIF) it.next();
109       if (channel.getId() == id) {
110         return channel;
111       }
112     }
113     return null;
114   }
115
116   public ChannelGroupIF getParent() {
117     return parent;
118   }
119
120   public void setParent(ChannelGroupIF parent) {
121     this.parent = parent;
122   }
123
124   public Collection JavaDoc getChildren() {
125     return children;
126   }
127
128   public void addChild(ChannelGroupIF child) {
129     children.add(child);
130     child.setParent(this);
131   }
132
133   public void removeChild(ChannelGroupIF child) {
134     children.remove(child);
135   }
136   
137   // ----------------------------------------------------------------------
138
// overwrite default method implementation from Object
139
// ----------------------------------------------------------------------
140

141   public String JavaDoc toString() {
142     return "[ChannelGroup (" + id + ")]";
143   }
144
145 }
146
Popular Tags