Bladeren bron

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 jaren geleden
bovenliggende
commit
7cdd4d3055
2 gewijzigde bestanden met toevoegingen van 5 en 47 verwijderingen
  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 Bestand weergeven

@@ -1,39 +0,0 @@
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 Bestand weergeven

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

Laden…
Annuleren
Opslaan