@Test public void purgeTillCommand() throws Exception { CommandBuffer buffer = new CommandBuffer(10); for (int i = 1; i <= 15; i++) { buffer.addCommand(createCmd(i)); if (i <= 11) { buffer.consumeCommand(); } } Assert.assertEquals(10, buffer.getBufferedCommandsCount()); buffer.purgeTillCommand(8); Assert.assertEquals(8, buffer.getBufferedCommandsCount()); buffer.purgeTillCommand(10); Assert.assertEquals(6, buffer.getBufferedCommandsCount()); buffer.purgeTillCommand(11); Assert.assertEquals(5, buffer.getBufferedCommandsCount()); buffer.purgeTillCommand(12); Assert.assertEquals("must not purge next consumable command", 4, buffer.getBufferedCommandsCount()); buffer.purgeTillCommand(100); Assert.assertEquals("must not purge next consumable command", 4, buffer.getBufferedCommandsCount()); }
public void purgeTillCommand(int commandIdExclusive) { while (buffer[tail].getId() != commandIdExclusive) { if (tail == nextConsumable) { LOGGER.error("Will not purge next consumable command!"); return; } buffer[tail] = null; tail = (tail + 1) % buffer.length; } }
CommandBuffer { public void purgeTillCommand(int commandIdExclusive) { while (buffer[tail].getId() != commandIdExclusive) { if (tail == nextConsumable) { LOGGER.error("Will not purge next consumable command!"); return; } buffer[tail] = null; tail = (tail + 1) % buffer.length; } } }
CommandBuffer { public void purgeTillCommand(int commandIdExclusive) { while (buffer[tail].getId() != commandIdExclusive) { if (tail == nextConsumable) { LOGGER.error("Will not purge next consumable command!"); return; } buffer[tail] = null; tail = (tail + 1) % buffer.length; } } CommandBuffer(int capacity); }
CommandBuffer { public void purgeTillCommand(int commandIdExclusive) { while (buffer[tail].getId() != commandIdExclusive) { if (tail == nextConsumable) { LOGGER.error("Will not purge next consumable command!"); return; } buffer[tail] = null; tail = (tail + 1) % buffer.length; } } CommandBuffer(int capacity); int getBufferedCommandsCount(); int getUnconsumedCommandsCount(); void addCommand(CMD command); CMD consumeCommand(); void purgeTillCommand(int commandIdExclusive); boolean rewindToCommand(long commandId); long getNextCommandId(); void clear(); }
CommandBuffer { public void purgeTillCommand(int commandIdExclusive) { while (buffer[tail].getId() != commandIdExclusive) { if (tail == nextConsumable) { LOGGER.error("Will not purge next consumable command!"); return; } buffer[tail] = null; tail = (tail + 1) % buffer.length; } } CommandBuffer(int capacity); int getBufferedCommandsCount(); int getUnconsumedCommandsCount(); void addCommand(CMD command); CMD consumeCommand(); void purgeTillCommand(int commandIdExclusive); boolean rewindToCommand(long commandId); long getNextCommandId(); void clear();  }