@Test public void testPullBeforeTime() { MemoryQueue.getInstance().offer(task1); MemoryQueue.getInstance().offer(task2); MemoryQueue.getInstance().offer(task3); MemoryQueue.getInstance().offer(task4); List<ExecutorTask> executorTaskList = MemoryQueue.getInstance().pullBeforeTime(System.currentTimeMillis() + 10); assertEquals(executorTaskList.size(), 3); assertTrue(executorTaskList.contains(task1)); assertTrue(executorTaskList.contains(task2)); assertTrue(executorTaskList.contains(task3)); assertTrue(!executorTaskList.contains(task4)); MemoryQueue.getInstance().clear(); assertEquals(MemoryQueue.getInstance().pullBeforeTime(0).size(), 0); }
public List<ExecutorTask> pullBeforeTime(long maxTime) { List<ExecutorTask> polledTasks = new ArrayList<ExecutorTask>(); ExecutorTask task; while ((task = queue.peek()) != null) { if (task.getCreateTime() <= maxTime) { polledTasks.add(task); queue.poll(); } else { break; } } return polledTasks; }
MemoryQueue { public List<ExecutorTask> pullBeforeTime(long maxTime) { List<ExecutorTask> polledTasks = new ArrayList<ExecutorTask>(); ExecutorTask task; while ((task = queue.peek()) != null) { if (task.getCreateTime() <= maxTime) { polledTasks.add(task); queue.poll(); } else { break; } } return polledTasks; } }
MemoryQueue { public List<ExecutorTask> pullBeforeTime(long maxTime) { List<ExecutorTask> polledTasks = new ArrayList<ExecutorTask>(); ExecutorTask task; while ((task = queue.peek()) != null) { if (task.getCreateTime() <= maxTime) { polledTasks.add(task); queue.poll(); } else { break; } } return polledTasks; }  }
MemoryQueue { public List<ExecutorTask> pullBeforeTime(long maxTime) { List<ExecutorTask> polledTasks = new ArrayList<ExecutorTask>(); ExecutorTask task; while ((task = queue.peek()) != null) { if (task.getCreateTime() <= maxTime) { polledTasks.add(task); queue.poll(); } else { break; } } return polledTasks; }  static MemoryQueue getInstance(); List<ExecutorTask> pullBeforeTime(long maxTime); boolean offer(ExecutorTask task); void clear(); }
MemoryQueue { public List<ExecutorTask> pullBeforeTime(long maxTime) { List<ExecutorTask> polledTasks = new ArrayList<ExecutorTask>(); ExecutorTask task; while ((task = queue.peek()) != null) { if (task.getCreateTime() <= maxTime) { polledTasks.add(task); queue.poll(); } else { break; } } return polledTasks; }  static MemoryQueue getInstance(); List<ExecutorTask> pullBeforeTime(long maxTime); boolean offer(ExecutorTask task); void clear();  }