DelayedTaskQueue { public boolean remove(DelayedTask task) { boolean wasRemoved = false; Iterator<Entry> iterator = tasks.iterator(); while (iterator.hasNext()) { Entry entry = iterator.next(); if (entry.task.equals(task)) { iterator.remove(); wasRemoved = true; } } return wasRemoved; } DelayedTaskQueue(); void add(DelayedTask task, long at); boolean remove(DelayedTask task); long nextTimeout(long now); void poll(long now);  }
@Test public void testRemove() { TestTask task1 = new TestTask(); TestTask task2 = new TestTask(); TestTask task3 = new TestTask(); scheduler.add(task1, 20); scheduler.add(task2, 10); scheduler.add(task3, 30); scheduler.add(task1, 40); assertEquals(10, scheduler.nextTimeout(0)); scheduler.remove(task2); assertEquals(20, scheduler.nextTimeout(0)); scheduler.remove(task1); assertEquals(30, scheduler.nextTimeout(0)); scheduler.remove(task3); assertEquals(Long.MAX_VALUE, scheduler.nextTimeout(0)); }