blob: e40ce2920988f8ed1d6f7f23630489d94c1dd81d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*******************************************************************************
* Copyright (c) 2003, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.framework.eventmgr;
import java.util.Map;
import java.util.Set;
/**
* This class manages a list of listeners.
*
* Listeners may be added or removed as necessary.
*
* This class uses identity for comparison, not equals.
*
* @since 3.1
* @deprecated As of 3.5. Replaced by CopyOnWriteIdentityMap.
* @noextend This class is not intended to be subclassed by clients.
*/
public class EventListeners<K, V> {
private final CopyOnWriteIdentityMap<K, V> list = new CopyOnWriteIdentityMap<>();
/**
* Creates an empty listener list.
*
*/
public EventListeners() {
super();
}
/**
* Creates an empty listener list.
*
* @param capacity This argument is ignored.
*/
public EventListeners(int capacity) {
this();
}
/**
* Add a listener to the list.
* If a listener object is already in the list, then it is replaced.
* This method calls the put method.
*
* @param listener This is the listener object to be added to the list.
* @param listenerObject This is an optional listener-specific object.
* This object will be passed to the EventDispatcher along with the listener
* when the listener is to be called. This may be null
* @throws IllegalArgumentException If listener is null.
*/
public void addListener(K listener, V listenerObject) {
list.put(listener, listenerObject);
}
/**
* Remove a listener from the list.
* This method calls the remove method.
*
* @param listener This is the listener object to be removed from the list.
* @throws IllegalArgumentException If listener is null.
*/
public void removeListener(V listener) {
list.remove(listener);
}
/**
* Remove all listeners from the list.
*
* This method calls the clear method.
*/
public void removeAllListeners() {
list.clear();
}
/**
* Get the entry Set from the internal CopyOnWriteIdentityMap.
* @return The entry Set.
*/
Set<Map.Entry<K, V>> entrySet() {
return list.entrySet();
}
}
|