Преглед изворни кода

Un-hideously-break everything with some kind of hacks.

Change-Id: I300d89360bbac9ae5fc193d7c4627ed2deb93c09
Reviewed-on: http://gerrit.dmdirc.com/1129
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.4
Chris Smith пре 14 година
родитељ
комит
67ac276841
1 измењених фајлова са 23 додато и 4 уклоњено
  1. 23
    4
      src/com/dmdirc/util/ListenerList.java

+ 23
- 4
src/com/dmdirc/util/ListenerList.java Прегледај датотеку

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.util;
24 24
 
25 25
 import java.util.Collection;
26
+import java.util.Comparator;
26 27
 import java.util.HashMap;
27 28
 import java.util.Map;
28 29
 import java.util.concurrent.ConcurrentSkipListSet;
@@ -34,6 +35,9 @@ import java.util.concurrent.ConcurrentSkipListSet;
34 35
  * @author chris
35 36
  */
36 37
 public class ListenerList {
38
+
39
+    /** The comparator to use. */
40
+    protected static EqualComparator COMPARATOR = new EqualComparator();
37 41
     
38 42
     /** The map of class->listener or string->listener that we're using. */
39 43
     private final Map<Object, Collection<Object>> listeners
@@ -54,7 +58,7 @@ public class ListenerList {
54 58
      */
55 59
     public <T> void add(final Class<T> listenerType, final T listener) {
56 60
         if (!listeners.containsKey(listenerType)) {
57
-            listeners.put(listenerType, new ConcurrentSkipListSet<Object>());
61
+            listeners.put(listenerType, new ConcurrentSkipListSet<Object>(COMPARATOR));
58 62
         }
59 63
 
60 64
         listeners.get(listenerType).add(listener);
@@ -68,7 +72,7 @@ public class ListenerList {
68 72
      */
69 73
     public void add(final String listenerType, final Object listener) {
70 74
         if (!listeners.containsKey(listenerType)) {
71
-            listeners.put(listenerType, new ConcurrentSkipListSet<Object>());
75
+            listeners.put(listenerType, new ConcurrentSkipListSet<Object>(COMPARATOR));
72 76
         }
73 77
 
74 78
         listeners.get(listenerType).add(listener);
@@ -108,7 +112,7 @@ public class ListenerList {
108 112
         if (listeners.containsKey(listenerType)) {
109 113
             return (Collection<T>) listeners.get(listenerType);
110 114
         } else {
111
-            return new ConcurrentSkipListSet<T>();
115
+            return new ConcurrentSkipListSet<T>(COMPARATOR);
112 116
         }
113 117
     }
114 118
     
@@ -122,8 +126,23 @@ public class ListenerList {
122 126
         if (listeners.containsKey(listenerType)) {
123 127
             return listeners.get(listenerType);
124 128
         } else {
125
-            return new ConcurrentSkipListSet<Object>();
129
+            return new ConcurrentSkipListSet<Object>(COMPARATOR);
130
+        }
131
+    }
132
+
133
+    /**
134
+     * A comparator that says any two objects are equal.
135
+     *
136
+     * @since 0.6.4
137
+     */
138
+    protected static class EqualComparator implements Comparator<Object> {
139
+
140
+        /** {@inheritDoc} */
141
+        @Override
142
+        public int compare(final Object o1, final Object o2) {
143
+            return 0;
126 144
         }
145
+
127 146
     }
128 147
 
129 148
 }

Loading…
Откажи
Сачувај