|
@@ -38,8 +38,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
38
|
38
|
public class ListenerList {
|
39
|
39
|
|
40
|
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
|
44
|
* Adds a new listener of the specified type to this listener list.
|
|
@@ -53,7 +52,7 @@ public class ListenerList {
|
53
|
52
|
throw new IllegalArgumentException("Listener cannot be null");
|
54
|
53
|
}
|
55
|
54
|
if (!listeners.containsKey(listenerType)) {
|
56
|
|
- listeners.put(listenerType, new CopyOnWriteArrayList<Object>());
|
|
55
|
+ listeners.put(listenerType, new CopyOnWriteArrayList<>());
|
57
|
56
|
}
|
58
|
57
|
|
59
|
58
|
listeners.get(listenerType).add(listener);
|
|
@@ -70,7 +69,7 @@ public class ListenerList {
|
70
|
69
|
throw new IllegalArgumentException("Listener cannot be null");
|
71
|
70
|
}
|
72
|
71
|
if (!listeners.containsKey(listenerType)) {
|
73
|
|
- listeners.put(listenerType, new CopyOnWriteArrayList<Object>());
|
|
72
|
+ listeners.put(listenerType, new CopyOnWriteArrayList<>());
|
74
|
73
|
}
|
75
|
74
|
|
76
|
75
|
listeners.get(listenerType).add(listener);
|
|
@@ -112,7 +111,7 @@ public class ListenerList {
|
112
|
111
|
if (listeners.containsKey(listenerType)) {
|
113
|
112
|
return (Collection<T>) listeners.get(listenerType);
|
114
|
113
|
} else {
|
115
|
|
- return new CopyOnWriteArrayList<T>();
|
|
114
|
+ return new CopyOnWriteArrayList<>();
|
116
|
115
|
}
|
117
|
116
|
}
|
118
|
117
|
|
|
@@ -126,7 +125,7 @@ public class ListenerList {
|
126
|
125
|
if (listeners.containsKey(listenerType)) {
|
127
|
126
|
return listeners.get(listenerType);
|
128
|
127
|
} else {
|
129
|
|
- return new CopyOnWriteArrayList<Object>();
|
|
128
|
+ return new CopyOnWriteArrayList<>();
|
130
|
129
|
}
|
131
|
130
|
}
|
132
|
131
|
|
|
@@ -141,7 +140,7 @@ public class ListenerList {
|
141
|
140
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
142
|
141
|
public <T> T getCallable(final Class<T> listenerType) {
|
143
|
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,20 +159,18 @@ public class ListenerList {
|
160
|
159
|
*
|
161
|
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
|
163
|
this.listenerType = listenerType;
|
165
|
164
|
}
|
166
|
165
|
|
167
|
166
|
/** {@inheritDoc} */
|
168
|
167
|
@Override
|
169
|
168
|
public Object invoke(final Object proxy, final Method method,
|
170
|
|
- final Object[] args) throws Throwable {
|
|
169
|
+ final Object[] args) throws Throwable {
|
171
|
170
|
for (T target : get(listenerType)) {
|
172
|
171
|
try {
|
173
|
172
|
method.invoke(target, args);
|
174
|
|
- } catch (IllegalAccessException ex) {
|
175
|
|
- // Ignore, not possible
|
176
|
|
- } catch (IllegalArgumentException ex) {
|
|
173
|
+ } catch (IllegalAccessException | IllegalArgumentException ex) {
|
177
|
174
|
// Ignore, not possible
|
178
|
175
|
} catch (InvocationTargetException ex) {
|
179
|
176
|
throw ex.getCause();
|