KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > ircfw > Channel


1 package rero.ircfw;
2
3 import java.util.*;
4
5 import rero.ircfw.interfaces.FrameworkConstants;
6 import rero.ircfw.data.*;
7
8 public class Channel implements FrameworkConstants, Comparator
9 {
10     protected String JavaDoc topic = ""; /* channel topic */
11
12     public void setTopic(String JavaDoc t) { topic = t; }
13     public String JavaDoc getTopic() { return topic; }
14
15     protected int limit; /* channel user limit */
16
17     public void setLimit(int l) { limit = l; }
18     public int getLimit() { return limit; }
19
20     protected String JavaDoc key; /* channel key */
21
22     public void setKey(String JavaDoc k) { key = k; }
23     public String JavaDoc getKey() { return key; }
24
25     protected GenericMode mode = new GenericMode(); /* channel mode */
26
27     public void setMode(String JavaDoc m) { mode = new GenericMode(m); }
28     public GenericMode getMode() { return mode; }
29
30     protected String JavaDoc name; /* name of this #channel */
31
32     public String JavaDoc getName() { return name; }
33   
34     public Channel(String JavaDoc name)
35     {
36        this.name = name;
37     }
38
39     protected SortedSet allusers = Collections.synchronizedSortedSet(new TreeSet(this)); // keep this synchronized or bad things will happen
40

41     public int compare(Object JavaDoc aa, Object JavaDoc bb)
42     {
43        User a = (User)aa;
44        User b = (User)bb;
45
46        if (a == null || b == null)
47           return 0;
48
49        int aM = a.getModeFor(this);
50        int bM = b.getModeFor(this);
51
52        int result = bM - aM;
53
54        if (result == 0)
55        {
56           return a.compareTo(b);
57        }
58
59        return result;
60     }
61
62     public Set getAllUsers()
63     {
64        return allusers; /* for now */
65     }
66
67     public String JavaDoc toString()
68     {
69        StringBuffer JavaDoc temp = new StringBuffer JavaDoc();
70        temp.append(getName());
71        temp.append(" \"");
72        temp.append(getTopic());
73        temp.append("\", ");
74
75        temp.append(getMode());
76  
77        if (getMode().isSet('k'))
78        {
79           temp.append(" key="+key);
80        }
81
82        if (getMode().isSet('l'))
83        {
84           temp.append(" limit="+limit);
85        }
86
87        temp.append(", ");
88
89        Iterator iter = getAllUsers().iterator();
90        while (iter.hasNext())
91        {
92            User tempa = (User)iter.next();
93            temp.append("?");
94            temp.append(tempa.getNick());
95            temp.append(" ");
96        }
97
98        return temp.toString();
99     }
100 }
101
Popular Tags