1 11 package org.eclipse.jdt.internal.launching; 12 13 14 17 public class ListenerList { 18 22 private int fSize; 23 24 29 private Object [] fListeners= null; 30 31 35 private static final Object [] EmptyArray= new Object [0]; 36 37 43 public ListenerList(int capacity) { 44 if (capacity < 1) { 45 throw new IllegalArgumentException (); 46 } 47 fListeners= new Object [capacity]; 48 fSize= 0; 49 } 50 51 57 public synchronized void add(Object listener) { 58 if (listener == null) { 59 throw new IllegalArgumentException (); 60 } 61 for (int i= 0; i < fSize; ++i) { 63 if (fListeners[i] == listener) { 64 return; 65 } 66 } 67 if (fSize == fListeners.length) { 69 Object [] temp= new Object [(fSize * 2) + 1]; 70 System.arraycopy(fListeners, 0, temp, 0, fSize); 71 fListeners= temp; 72 } 73 fListeners[fSize++]= listener; 74 } 75 76 85 public synchronized Object [] getListeners() { 86 if (fSize == 0) { 87 return EmptyArray; 88 } 89 Object [] result= new Object [fSize]; 90 System.arraycopy(fListeners, 0, result, 0, fSize); 91 return result; 92 } 93 94 100 public synchronized void remove(Object listener) { 101 if (listener == null) { 102 throw new IllegalArgumentException (); 103 } 104 105 for (int i= 0; i < fSize; ++i) { 106 if (fListeners[i] == listener) { 107 if (--fSize == 0) { 108 fListeners= new Object [1]; 109 } else { 110 if (i < fSize) { 111 fListeners[i]= fListeners[fSize]; 112 } 113 fListeners[fSize]= null; 114 } 115 return; 116 } 117 } 118 } 119 120 123 public void removeAll() { 124 fListeners= new Object [0]; 125 fSize= 0; 126 } 127 128 133 public int size() { 134 return fSize; 135 } 136 } 137 138 | Popular Tags |