/** * Removes all the entries specifying a given observer from the receiver’s dispatch table. */ public synchronized void removeObserver(final ApptentiveNotificationObserver observer) { for (ApptentiveNotificationObserverList observers : observerListLookup.values()) { observers.removeObserver(observer); } }
/** * Removes matching entries from the receiver’s dispatch table. */ public synchronized void removeObserver(final String notification, final ApptentiveNotificationObserver observer) { final ApptentiveNotificationObserverList list = findObserverList(notification); if (list != null) { list.removeObserver(observer); } }
@Override public void onReceiveNotification(ApptentiveNotification notification) { list.removeObserver(o1); addResult("anonymous-observer1"); } }, STRONG_REFERENCE);
@Override public void onReceiveNotification(ApptentiveNotification notification) { list.removeObserver(o2); addResult("anonymous-observer2"); } }, STRONG_REFERENCE);
@Test public void testRemoveObservers() { ApptentiveNotificationObserverList list = new ApptentiveNotificationObserverList(); Observer o1 = new Observer("observer1"); Observer o2 = new Observer("observer2"); list.addObserver(o1, WEAK_REFERENCE); list.addObserver(o2, STRONG_REFERENCE); list.notifyObservers(new ApptentiveNotification("notification", new HashMap<String, Object>())); assertResult("observer1", "observer2"); assertEquals(2, list.size()); list.removeObserver(o1); assertEquals(1, list.size()); list.notifyObservers(new ApptentiveNotification("notification", new HashMap<String, Object>())); assertResult("observer2"); list.removeObserver(o2); list.notifyObservers(new ApptentiveNotification("notification", new HashMap<String, Object>())); assertResult(); assertEquals(0, list.size()); }