1 19 20 package org.openide.filesystems; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 26 31 class ListenerList<T> { 32 private final List <T> listenerList; 33 private List <T> copy = null; 34 35 ListenerList() { 36 listenerList = new ArrayList <T>(); 37 } 38 39 42 public synchronized boolean add(T listener) { 43 if (listener == null) { 44 throw new NullPointerException (); 45 } 46 47 copy = null; 48 49 return listenerList.add(listener); 50 } 51 52 55 public synchronized boolean remove(T listener) { 56 copy = null; 57 58 return listenerList.remove(listener); 59 } 60 61 64 public synchronized List <T> getAllListeners() { 65 if (copy == null) { 66 copy = new ArrayList <T>(listenerList); 67 } 68 return copy; 69 } 70 71 public synchronized boolean hasListeners() { 72 return !listenerList.isEmpty(); 73 } 74 75 } 76 | Popular Tags |