### Question:
ListIndex implements Index<Key,Value> { synchronized public Value addFirst(Transaction tx, Key key, Value value) throws IOException { assertLoaded(); getHead(tx).addFirst(tx, key, value); size.incrementAndGet(); flushCache(); return null; } ListIndex();  ListIndex(PageFile pageFile, long headPageId); @SuppressWarnings("rawtypes")  ListIndex(PageFile pageFile, Page page); @Override synchronized void load(Transaction tx); @Override synchronized void unload(Transaction tx); @Override synchronized boolean containsKey(Transaction tx, Key key); @Override @SuppressWarnings({ "rawtypes", "unchecked" }) synchronized Value get(Transaction tx, Key key); @Override @SuppressWarnings({ "rawtypes" }) synchronized Value put(Transaction tx, Key key, Value value); synchronized Value add(Transaction tx, Key key, Value value); synchronized Value addFirst(Transaction tx, Key key, Value value); @Override @SuppressWarnings("rawtypes") synchronized Value remove(Transaction tx, Key key); void onRemove(Entry<Key, Value> removed); @Override boolean isTransient(); @Override synchronized void clear(Transaction tx); synchronized Iterator<ListNode<Key, Value>> listNodeIterator(Transaction tx); synchronized boolean isEmpty(final Transaction tx); @Override synchronized Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx); synchronized Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx, long initialPosition); synchronized Map.Entry<Key,Value> getFirst(Transaction tx); synchronized Map.Entry<Key,Value> getLast(Transaction tx); ListNode<Key,Value> createNode(Transaction tx); void storeNode(Transaction tx, ListNode<Key,Value> node, boolean overflow); PageFile getPageFile(); void setPageFile(PageFile pageFile); long getHeadPageId(); void setHeadPageId(long headPageId); Marshaller<Key> getKeyMarshaller(); @Override void setKeyMarshaller(Marshaller<Key> keyMarshaller); Marshaller<Value> getValueMarshaller(); @Override void setValueMarshaller(Marshaller<Value> valueMarshaller); void setTailPageId(long tailPageId); long getTailPageId(); long size(); final static long NOT_SET; }### Answer:
@Test(timeout=60000) public void testAddFirst() throws Exception { createPageFileAndIndex(100); ListIndex<String, Long> listIndex = ((ListIndex<String, Long>) this.index); this.index.load(tx); tx.commit(); tx = pf.tx(); doInsert(10); listIndex.addFirst(tx, key(10), (long) 10); listIndex.addFirst(tx, key(11), (long) 11); tx.commit(); tx = pf.tx(); int counter = 11; Iterator<Map.Entry<String, Long>> iterator = index.iterator(tx); assertEquals(key(counter), iterator.next().getKey()); counter--; assertEquals(key(counter), iterator.next().getKey()); counter--; int count = 0; while (iterator.hasNext() && count < counter) { Map.Entry<String, Long> entry = iterator.next(); assertEquals(key(count), entry.getKey()); assertEquals(count, (long) entry.getValue()); count++; } tx.commit(); }