@Test public void testRemove() throws InterruptedException { Listener listener = new Listener() { @Override public void exec() { Assert.fail("Should have been removed"); } }; weakListeners.add(listener); weakListeners.remove(listener); weakListeners.fire(new WeakListeners.Action<Listener>() { @Override public void fire(Listener listener) { listener.exec(); } }); }
public void remove(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null || theListener.equals(listener)) { it.remove(); } } } }
WeakListeners { public void remove(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null || theListener.equals(listener)) { it.remove(); } } } } }
WeakListeners { public void remove(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null || theListener.equals(listener)) { it.remove(); } } } }  }
WeakListeners { public void remove(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null || theListener.equals(listener)) { it.remove(); } } } }  void fire(Action<E> action); void add(E listener, boolean weak); void add(E listener); void remove(E listener); boolean isRegistered(E listener); }
WeakListeners { public void remove(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null || theListener.equals(listener)) { it.remove(); } } } }  void fire(Action<E> action); void add(E listener, boolean weak); void add(E listener); void remove(E listener); boolean isRegistered(E listener);  }