CachedIndex implements LookupIndexIF<K, E> { protected void prune() { prunings++; for (int ix = 0; ix < data.length; ix++) { Entry current = data[ix]; Entry previous = null; while (current != null) { if (current.hits < decay) { if (previous == null) data[ix] = current.next; else previous.next = current.next; entries--; } else current.hits -= decay; current = current.next; } } } CachedIndex(LookupIndexIF<K, E> fallback);  CachedIndex(LookupIndexIF<K, E> fallback, boolean nulls);  CachedIndex(LookupIndexIF<K, E> fallback, int max, int size, boolean nulls); @Override E get(K key); @Override E put(K key, E value); @Override E remove(K key); int getKeyNumber(); void writeReport();  }
@Test public void testPrune() { index = new CachedIndex(new SameIndex(), 250, 5, true); for (int ix = 0; ix < 10000; ix++) { String key = Integer.toString((int) (Math.random() * 500)); Assert.assertTrue("didn't find value", index.get(key).equals(key)); } Assert.assertTrue("number of keys in index too high", index.getKeyNumber() <= 250); }