FifoLinkedList { public int getIndex(final InternalNode node) { final int seqNum = node.seqNum; if (seqNum < 1) { return -1; } return length - (seqNum - master.previous.seqNum) - 1; } FifoLinkedList(); Header get(final int index); int getIndex(final InternalNode node); Header getFirst(); Header getLast(); int size(); InternalNode addFirst(final HPackHeader header); InternalNode removeLast(); void clear();  }
@Test public void testGetIndex() throws Exception { final FifoLinkedList fifoLinkedList = new FifoLinkedList(); final HPackHeader h1 = new HPackHeader("h", "1"); final HPackHeader h2 = new HPackHeader("h", "2"); final HPackHeader h3 = new HPackHeader("h", "3"); final HPackHeader h4 = new HPackHeader("h", "4"); final FifoLinkedList.InternalNode node1 = fifoLinkedList.addFirst(h1); final FifoLinkedList.InternalNode node2 = fifoLinkedList.addFirst(h2); final FifoLinkedList.InternalNode node3 = fifoLinkedList.addFirst(h3); final FifoLinkedList.InternalNode node4 = fifoLinkedList.addFirst(h4); Assert.assertEquals(0, fifoLinkedList.getIndex(node4)); Assert.assertEquals(1, fifoLinkedList.getIndex(node3)); Assert.assertEquals(2, fifoLinkedList.getIndex(node2)); Assert.assertEquals(3, fifoLinkedList.getIndex(node1)); Assert.assertEquals(4, fifoLinkedList.size()); Assert.assertSame(h4, fifoLinkedList.get(0)); Assert.assertSame(h3, fifoLinkedList.get(1)); Assert.assertSame(h2, fifoLinkedList.get(2)); Assert.assertSame(h1, fifoLinkedList.get(3)); fifoLinkedList.removeLast(); Assert.assertEquals(0, fifoLinkedList.getIndex(node4)); Assert.assertEquals(1, fifoLinkedList.getIndex(node3)); Assert.assertEquals(2, fifoLinkedList.getIndex(node2)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node1)); Assert.assertEquals(3, fifoLinkedList.size()); Assert.assertSame(h4, fifoLinkedList.get(0)); Assert.assertSame(h3, fifoLinkedList.get(1)); Assert.assertSame(h2, fifoLinkedList.get(2)); fifoLinkedList.removeLast(); Assert.assertEquals(0, fifoLinkedList.getIndex(node4)); Assert.assertEquals(1, fifoLinkedList.getIndex(node3)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node2)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node1)); Assert.assertEquals(2, fifoLinkedList.size()); Assert.assertSame(h4, fifoLinkedList.get(0)); Assert.assertSame(h3, fifoLinkedList.get(1)); fifoLinkedList.removeLast(); Assert.assertEquals(0, fifoLinkedList.getIndex(node4)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node3)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node2)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node1)); Assert.assertEquals(1, fifoLinkedList.size()); Assert.assertSame(h4, fifoLinkedList.get(0)); fifoLinkedList.removeLast(); Assert.assertEquals(-1, fifoLinkedList.getIndex(node4)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node3)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node2)); Assert.assertEquals(-1, fifoLinkedList.getIndex(node1)); Assert.assertEquals(0, fifoLinkedList.size()); }