@Test public void testIsRegistered() { Listener listener = new Listener() { @Override public void exec() { } }; Assert.assertFalse(weakListeners.isRegistered(listener)); weakListeners.add(listener, false); Assert.assertTrue(weakListeners.isRegistered(listener)); }
public boolean isRegistered(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null) { it.remove(); } else if(theListener.equals(listener)) { return true; } } return false; } }
WeakListeners { public boolean isRegistered(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null) { it.remove(); } else if(theListener.equals(listener)) { return true; } } return false; } } }
WeakListeners { public boolean isRegistered(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null) { it.remove(); } else if(theListener.equals(listener)) { return true; } } return false; } }  }
WeakListeners { public boolean isRegistered(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null) { it.remove(); } else if(theListener.equals(listener)) { return true; } } return false; } }  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 boolean isRegistered(E listener) { synchronized (listeners) { for(Iterator<MyReference<E>> it = listeners.iterator(); it.hasNext(); ) { E theListener = it.next().get(); if(theListener == null) { it.remove(); } else if(theListener.equals(listener)) { return true; } } return false; } }  void fire(Action<E> action); void add(E listener, boolean weak); void add(E listener); void remove(E listener); boolean isRegistered(E listener);  }