Browse Source

Fix stupid listener list issues

Change-Id: I9cf9e071a8e1c134026b50e78de569def85eda56
Reviewed-on: http://gerrit.dmdirc.com/1136
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Chris Smith 14 years ago
parent
commit
7cdd4d3055
2 changed files with 5 additions and 47 deletions
  1. 0
    39
      src/com/dmdirc/util/EqualComparator.java
  2. 5
    8
      src/com/dmdirc/util/ListenerList.java

+ 0
- 39
src/com/dmdirc/util/EqualComparator.java View File

1
-/*
2
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.util;
24
-
25
-import java.util.Comparator;
26
-
27
-/**
28
- * A comparator that says any two objects are equal.
29
- *
30
- * @since 0.6.4
31
- */
32
-public class EqualComparator implements Comparator<Object> {
33
-
34
-    /** {@inheritDoc} */
35
-    @Override
36
-    public int compare(final Object o1, final Object o2) {
37
-        return 0;
38
-    }
39
-}

+ 5
- 8
src/com/dmdirc/util/ListenerList.java View File

25
 import java.util.Collection;
25
 import java.util.Collection;
26
 import java.util.HashMap;
26
 import java.util.HashMap;
27
 import java.util.Map;
27
 import java.util.Map;
28
-import java.util.concurrent.ConcurrentSkipListSet;
28
+import java.util.concurrent.CopyOnWriteArrayList;
29
 
29
 
30
 /**
30
 /**
31
  * Represents a list of event listeners, similar to EventListenerList, but
31
  * Represents a list of event listeners, similar to EventListenerList, but
34
  * @author chris
34
  * @author chris
35
  */
35
  */
36
 public class ListenerList {
36
 public class ListenerList {
37
-
38
-    /** The comparator to use. */
39
-    protected static EqualComparator COMPARATOR = new EqualComparator();
40
     
37
     
41
     /** The map of class->listener or string->listener that we're using. */
38
     /** The map of class->listener or string->listener that we're using. */
42
     private final Map<Object, Collection<Object>> listeners
39
     private final Map<Object, Collection<Object>> listeners
57
      */
54
      */
58
     public <T> void add(final Class<T> listenerType, final T listener) {
55
     public <T> void add(final Class<T> listenerType, final T listener) {
59
         if (!listeners.containsKey(listenerType)) {
56
         if (!listeners.containsKey(listenerType)) {
60
-            listeners.put(listenerType, new ConcurrentSkipListSet<Object>(COMPARATOR));
57
+            listeners.put(listenerType, new CopyOnWriteArrayList<Object>());
61
         }
58
         }
62
 
59
 
63
         listeners.get(listenerType).add(listener);
60
         listeners.get(listenerType).add(listener);
71
      */
68
      */
72
     public void add(final String listenerType, final Object listener) {
69
     public void add(final String listenerType, final Object listener) {
73
         if (!listeners.containsKey(listenerType)) {
70
         if (!listeners.containsKey(listenerType)) {
74
-            listeners.put(listenerType, new ConcurrentSkipListSet<Object>(COMPARATOR));
71
+            listeners.put(listenerType, new CopyOnWriteArrayList<Object>());
75
         }
72
         }
76
 
73
 
77
         listeners.get(listenerType).add(listener);
74
         listeners.get(listenerType).add(listener);
111
         if (listeners.containsKey(listenerType)) {
108
         if (listeners.containsKey(listenerType)) {
112
             return (Collection<T>) listeners.get(listenerType);
109
             return (Collection<T>) listeners.get(listenerType);
113
         } else {
110
         } else {
114
-            return new ConcurrentSkipListSet<T>(COMPARATOR);
111
+            return new CopyOnWriteArrayList<T>();
115
         }
112
         }
116
     }
113
     }
117
     
114
     
125
         if (listeners.containsKey(listenerType)) {
122
         if (listeners.containsKey(listenerType)) {
126
             return listeners.get(listenerType);
123
             return listeners.get(listenerType);
127
         } else {
124
         } else {
128
-            return new ConcurrentSkipListSet<Object>(COMPARATOR);
125
+            return new CopyOnWriteArrayList<Object>();
129
         }
126
         }
130
     }
127
     }
131
 
128
 

Loading…
Cancel
Save