Browse Source

Tidying

Change-Id: If6b2a1a485ff5b3a2630b43c76422064aaa2efb7
Reviewed-on: http://gerrit.dmdirc.com/2806
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
changes/06/2806/2
Chris Smith 10 years ago
parent
commit
18d85e6a10
1 changed files with 9 additions and 12 deletions
  1. 9
    12
      src/com/dmdirc/util/collections/ListenerList.java

+ 9
- 12
src/com/dmdirc/util/collections/ListenerList.java View File

38
 public class ListenerList {
38
 public class ListenerList {
39
 
39
 
40
     /** The map of class->listener or string->listener that we're using. */
40
     /** The map of class->listener or string->listener that we're using. */
41
-    private final Map<Object, Collection<Object>> listeners
42
-            = new HashMap<Object, Collection<Object>>();
41
+    private final Map<Object, Collection<Object>> listeners = new HashMap<>();
43
 
42
 
44
     /**
43
     /**
45
      * Adds a new listener of the specified type to this listener list.
44
      * Adds a new listener of the specified type to this listener list.
53
             throw new IllegalArgumentException("Listener cannot be null");
52
             throw new IllegalArgumentException("Listener cannot be null");
54
         }
53
         }
55
         if (!listeners.containsKey(listenerType)) {
54
         if (!listeners.containsKey(listenerType)) {
56
-            listeners.put(listenerType, new CopyOnWriteArrayList<Object>());
55
+            listeners.put(listenerType, new CopyOnWriteArrayList<>());
57
         }
56
         }
58
 
57
 
59
         listeners.get(listenerType).add(listener);
58
         listeners.get(listenerType).add(listener);
70
             throw new IllegalArgumentException("Listener cannot be null");
69
             throw new IllegalArgumentException("Listener cannot be null");
71
         }
70
         }
72
         if (!listeners.containsKey(listenerType)) {
71
         if (!listeners.containsKey(listenerType)) {
73
-            listeners.put(listenerType, new CopyOnWriteArrayList<Object>());
72
+            listeners.put(listenerType, new CopyOnWriteArrayList<>());
74
         }
73
         }
75
 
74
 
76
         listeners.get(listenerType).add(listener);
75
         listeners.get(listenerType).add(listener);
112
         if (listeners.containsKey(listenerType)) {
111
         if (listeners.containsKey(listenerType)) {
113
             return (Collection<T>) listeners.get(listenerType);
112
             return (Collection<T>) listeners.get(listenerType);
114
         } else {
113
         } else {
115
-            return new CopyOnWriteArrayList<T>();
114
+            return new CopyOnWriteArrayList<>();
116
         }
115
         }
117
     }
116
     }
118
 
117
 
126
         if (listeners.containsKey(listenerType)) {
125
         if (listeners.containsKey(listenerType)) {
127
             return listeners.get(listenerType);
126
             return listeners.get(listenerType);
128
         } else {
127
         } else {
129
-            return new CopyOnWriteArrayList<Object>();
128
+            return new CopyOnWriteArrayList<>();
130
         }
129
         }
131
     }
130
     }
132
 
131
 
141
     @SuppressWarnings({"unchecked", "rawtypes"})
140
     @SuppressWarnings({"unchecked", "rawtypes"})
142
     public <T> T getCallable(final Class<T> listenerType) {
141
     public <T> T getCallable(final Class<T> listenerType) {
143
         return (T) Proxy.newProxyInstance(listenerType.getClassLoader(),
142
         return (T) Proxy.newProxyInstance(listenerType.getClassLoader(),
144
-                new Class[] { listenerType }, new CallHandler<T>(listenerType));
143
+                new Class[] { listenerType }, new CallHandler<>(listenerType));
145
     }
144
     }
146
 
145
 
147
     /**
146
     /**
160
          *
159
          *
161
          * @param listenerType The type of listener to handle
160
          * @param listenerType The type of listener to handle
162
          */
161
          */
163
-        public CallHandler(final Class<T> listenerType) {
162
+        CallHandler(final Class<T> listenerType) {
164
             this.listenerType = listenerType;
163
             this.listenerType = listenerType;
165
         }
164
         }
166
 
165
 
167
         /** {@inheritDoc} */
166
         /** {@inheritDoc} */
168
         @Override
167
         @Override
169
         public Object invoke(final Object proxy, final Method method,
168
         public Object invoke(final Object proxy, final Method method,
170
-            final Object[] args) throws Throwable {
169
+                final Object[] args) throws Throwable {
171
             for (T target : get(listenerType)) {
170
             for (T target : get(listenerType)) {
172
                 try {
171
                 try {
173
                     method.invoke(target, args);
172
                     method.invoke(target, args);
174
-                } catch (IllegalAccessException ex) {
175
-                    // Ignore, not possible
176
-                } catch (IllegalArgumentException ex) {
173
+                } catch (IllegalAccessException | IllegalArgumentException ex) {
177
                     // Ignore, not possible
174
                     // Ignore, not possible
178
                 } catch (InvocationTargetException ex) {
175
                 } catch (InvocationTargetException ex) {
179
                     throw ex.getCause();
176
                     throw ex.getCause();

Loading…
Cancel
Save