1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.peer;
21
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25
26 import org.xnap.event.ListListener;
27 import org.xnap.event.ListSupport;
28
29 /***
30 * Manages {@link HotlistItem} objects.
31 */
32 public class HotlistManager
33 {
34
35
36
37
38
39 private static HotlistManager instance = new HotlistManager();
40
41 /***
42 * A list of {@link HotlistItem} objects.
43 */
44 private List items = new LinkedList();
45
46 private ListSupport lsItems = new ListSupport(this);
47
48
49
50 private HotlistManager()
51 {
52 }
53
54
55
56 /***
57 * Returns the instance of HotlistManager.
58 */
59 public static HotlistManager getInstance()
60 {
61 return instance;
62 }
63
64 /***
65 * Adds <code>item</code> to the hotlist.
66 */
67 public synchronized void add(HotlistItem item)
68 {
69 items.add(item);
70 lsItems.fireItemAdded(item);
71 }
72
73 /***
74 * <code>Listener</code> is notified when a new item is added or removed.
75 */
76 public synchronized void addListListener(ListListener listener)
77 {
78 lsItems.addListListener(listener);
79 }
80
81 public synchronized HotlistItem[] getItems()
82 {
83 return (HotlistItem[])items.toArray(new HotlistItem[0]);
84 }
85
86 /***
87 * Removes <code>item</code> from the hotlist.
88 */
89 public synchronized void remove(HotlistItem item)
90 {
91 items.remove(item);
92 lsItems.fireItemRemoved(item);
93 }
94
95 /***
96 * Removes all items of class <code>itemClass</code> from the hotlist.
97 */
98 public synchronized void removeByClass(Class itemClass)
99 {
100 for (Iterator i = items.iterator(); i.hasNext();) {
101 HotlistItem item = (HotlistItem)i.next();
102 if (item.getClass() == itemClass) {
103 i.remove();
104 lsItems.fireItemRemoved(item);
105 }
106 }
107 }
108
109 /***
110 *
111 */
112 public void removeListListener(ListListener listener)
113 {
114 lsItems.removeListListener(listener);
115 }
116
117 }