### Question:
ListIndex implements Index<Key,Value> { @Override @SuppressWarnings({ "rawtypes" }) synchronized public Value put(Transaction tx, Key key, Value value) throws IOException { Value oldValue = null; if (lastGetNodeCache != null && tx.equals(lastCacheTxSrc.get())) { if(lastGetEntryCache.getKey().equals(key)) { oldValue = lastGetEntryCache.setValue(value); lastGetEntryCache.setValue(value); lastGetNodeCache.storeUpdate(tx); flushCache(); return oldValue; } Iterator<Map.Entry<Key, Value>> iterator = lastGetNodeCache.iterator(tx); while (iterator.hasNext()) { Map.Entry<Key, Value> entry = iterator.next(); if (entry.getKey().equals(key)) { oldValue = entry.setValue(value); ((ListIterator) iterator).getCurrent().storeUpdate(tx); flushCache(); return oldValue; } } } else { flushCache(); } Iterator<Map.Entry<Key, Value>> iterator = iterator(tx); while (iterator.hasNext() && ((ListIterator) iterator).getCurrent() != lastGetNodeCache) { Map.Entry<Key, Value> entry = iterator.next(); if (entry.getKey().equals(key)) { oldValue = entry.setValue(value); ((ListIterator) iterator).getCurrent().storeUpdate(tx); flushCache(); return oldValue; } } flushCache(); return add(tx, key, value); } 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 testPut() throws Exception { createPageFileAndIndex(100); ListIndex<String, Long> listIndex = ((ListIndex<String, Long>) this.index); this.index.load(tx); tx.commit(); int count = 30; tx = pf.tx(); doInsert(count); tx.commit(); assertEquals("correct size", count, listIndex.size()); tx = pf.tx(); Long value = listIndex.get(tx, key(10)); assertNotNull(value); listIndex.put(tx, key(10), Long.valueOf(1024)); tx.commit(); tx = pf.tx(); value = listIndex.get(tx, key(10)); assertEquals(1024L, value.longValue()); assertTrue(listIndex.size() == 30); tx.commit(); tx = pf.tx(); value = listIndex.put(tx, key(31), Long.valueOf(2048)); assertNull(value); assertTrue(listIndex.size() == 31); tx.commit(); }