1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.xdebug.core;
13 import java.util.HashMap;
17 * Local version of org.eclipse.jface.util.ListenerList (modified)s
19 public class ListenerMap {
21 * The current number of listeners.
22 * Maintains invariant: 0 <= fSize <= listeners.length.
27 * The map of listeners. Initially <code>null</code> but initialized
28 * to an array of size capacity the first time a listener is added.
29 * Maintains invariant: listeners != null if and only if fSize != 0
31 private HashMap fListeners = null;
32 // private HashMap<String,Object> fListeners = null;
35 * Creates a listener map with the given initial capacity.
37 * @param capacity the number of listeners which this list can initially accept
38 * without growing its internal representation; must be at least 1
40 public ListenerMap(int capacity) {
42 throw new IllegalArgumentException();
44 fListeners = new HashMap(capacity);
49 * Adds a listener to the Map.
50 * Overwrites an existing listener with the same IDE_Key.
52 * @param listener a listener
53 * @param ideKey IDE-key of the listener
55 public synchronized void add(Object listener,String ideKey) {
56 if (listener == null) {
57 throw new IllegalArgumentException();
59 // check for duplicates using identity
60 if (fListeners.get(ideKey) != null)
62 fListeners.put(ideKey,listener);
66 * Returns a map containing all the registered listeners.
67 * The resulting map is unaffected by subsequent adds or removes.
68 * If there are no listeners registered, the result is an empty map.
69 * Use this method when notifying listeners, so that any modifications
70 * to the listener list during the notification will have no effect on the
71 * notification itself.
73 public synchronized HashMap getListeners() {
77 HashMap result = new HashMap(fListeners);
82 * Returns the listener associated with the ideKey.
83 * If there is no listener registered, the result is null.
84 * Use this method when notifying listeners, so that any modifications
85 * to the listener list during the notification will have no effect on the
86 * notification itself.
88 public synchronized Object getListener(String ideKey) {
89 return fListeners.get(ideKey);
93 * Removes a listener from the list.
94 * Has no effect if an identical listener was not already registered.
96 * @param listener a listener
98 public synchronized void remove(Object listener,String ideKey) {
99 if (listener == null) {
100 throw new IllegalArgumentException();
103 if (fListeners.get(ideKey) == listener) {
104 fListeners.remove(ideKey);
110 * Removes all the listeners from the list.
112 public synchronized void removeAll() {
118 * Returns the number of registered listeners
120 * @return the number of registered listeners