Source:
public Iterator<Cache.Entry<K, ValueHolder<V>>> iterator() { final java.util.Iterator<Map.Entry<K, OnHeapValueHolder<V>>> it = map.entrySetIterator(); return new Iterator<Cache.Entry<K, ValueHolder<V>>>() { private Map.Entry<K, OnHeapValueHolder<V>> next = null; private CacheAccessException prefetchFailure = null; { advance(); } private void advance() { next = null; try { while (next == null && it.hasNext()) { Map.Entry<K, OnHeapValueHolder<V>> entry = it.next(); final long now = timeSource.getTimeMillis(); if (entry.getValue().isExpired(now, TimeUnit.MILLISECONDS)) { internalGet(entry.getKey(), false); continue; } next = entry; } } catch (RuntimeException re) { prefetchFailure = new CacheAccessException(re); } catch (CacheAccessException e) { prefetchFailure = e; } } @Override public boolean hasNext() { return next != null || prefetchFailure != null; } @Override public Cache.Entry<K, ValueHolder<V>> next() throws CacheAccessException { if(prefetchFailure != null) { throw prefetchFailure; } if (next == null) { throw new NoSuchElementException(); } final Map.Entry<K, OnHeapValueHolder<V>> thisEntry = next; advance(); if (setAccessTimeAndExpiry(thisEntry.getKey(), thisEntry.getValue(), timeSource.getTimeMillis()) == null) { onExpiration(thisEntry.getKey(), thisEntry.getValue()); advance(); } return new Cache.Entry<K, ValueHolder<V>>() { @Override public K getKey() { return thisEntry.getKey(); } @Override public ValueHolder<V> getValue() { return thisEntry.getValue(); } @Override public long getCreationTime(TimeUnit unit) { return thisEntry.getValue().creationTime(unit); } @Override public long getLastAccessTime(TimeUnit unit) { return thisEntry.getValue().lastAccessTime(unit); } @Override public float getHitRate(TimeUnit unit) { final long now = timeSource.getTimeMillis(); return thisEntry.getValue().hitRate(now, unit); } }; } }; }

Target:
public Iterator<Cache.Entry<K, ValueHolder<V>>> iterator() { final java.util.Iterator<Map.Entry<K, OnHeapValueHolder<V>>> it = map.entrySetIterator(); return new Iterator<Cache.Entry<K, ValueHolder<V>>>() { private Map.Entry<K, OnHeapValueHolder<V>> next = null; private CacheAccessException prefetchFailure = null; { advance(); } private void advance() { next = null; try { while (next == null && it.hasNext()) { Map.Entry<K, OnHeapValueHolder<V>> entry = it.next(); final long now = timeSource.getTimeMillis(); if (entry.getValue().isExpired(now, TimeUnit.MILLISECONDS)) { internalGet(entry.getKey(), false); continue; } next = entry; } } catch (RuntimeException re) { prefetchFailure = new CacheAccessException(re); } catch (CacheAccessException e) { prefetchFailure = e; } } @Override public boolean hasNext() { return next != null || prefetchFailure != null; } @Override public Cache.Entry<K, ValueHolder<V>> next() throws CacheAccessException { if(prefetchFailure != null) { throw prefetchFailure; } if (next == null) { throw new NoSuchElementException(); } final Map.Entry<K, OnHeapValueHolder<V>> thisEntry = next; advance(); setAccessTimeAndExpiryThenReturnMapping(thisEntry.getKey(), thisEntry.getValue(), timeSource.getTimeMillis(), true); return new Cache.Entry<K, ValueHolder<V>>() { @Override public K getKey() { return thisEntry.getKey(); } @Override public ValueHolder<V> getValue() { return thisEntry.getValue(); } @Override public long getCreationTime(TimeUnit unit) { return thisEntry.getValue().creationTime(unit); } @Override public long getLastAccessTime(TimeUnit unit) { return thisEntry.getValue().lastAccessTime(unit); } @Override public float getHitRate(TimeUnit unit) { final long now = timeSource.getTimeMillis(); return thisEntry.getValue().hitRate(now, unit); } }; } }; }