protected void removeRencentlyLeastAccess(  
            Set<Map.Entry<K, ValueEntry>> entries) {  
        // 最小使用次数  
        int least = 0;  
        // 最久没有被访问  
        long earliest = 0;  
        K toBeRemovedByCount = null;  
        K toBeRemovedByTime = null;  
        Iterator<Map.Entry<K, ValueEntry>> it = entries.iterator();  
        if (it.hasNext()) {  
            Map.Entry<K, ValueEntry> valueEntry = it.next();  
            least = valueEntry.getValue().count.get();  
            toBeRemovedByCount = valueEntry.getKey();  
            earliest = valueEntry.getValue().lastAccess.get();  
            toBeRemovedByTime = valueEntry.getKey();  
        }  
        while (it.hasNext()) {  
            Map.Entry<K, ValueEntry> valueEntry = it.next();  
            if (valueEntry.getValue().count.get() < least) {  
                least = valueEntry.getValue().count.get();  
                toBeRemovedByCount = valueEntry.getKey();  
            }  
            if (valueEntry.getValue().lastAccess.get() < earliest) {  
                earliest = valueEntry.getValue().count.get();  
                toBeRemovedByTime = valueEntry.getKey();  
            }  
        }  
        // System.out.println("remove:" + toBeRemoved);  
        // 如果最少使用次数大于MINI_ACCESS，那么移除访问时间最早的项(也就是最久没有被访问的项）  
        if (least > MINI_ACCESS) {  
            map.remove(toBeRemovedByTime);  
        } else {  
            map.remove(toBeRemovedByCount);  
        }  
    }
protected void removeRencentlyLeastAccess ( Set < Map . Entry < K , ValueEntry > > entries ) { int least = 0 ; long earliest = 0 ; K toBeRemovedByCount = null ; K toBeRemovedByTime = null ; Iterator < Map . Entry < K , ValueEntry > > it = entries . iterator ( ) ; if ( it . hasNext ( ) ) { Map . Entry < K , ValueEntry > valueEntry = it . next ( ) ; least = valueEntry . getValue ( ) . count . get ( ) ; toBeRemovedByCount = valueEntry . getKey ( ) ; earliest = valueEntry . getValue ( ) . lastAccess . get ( ) ; toBeRemovedByTime = valueEntry . getKey ( ) ; } while ( it . hasNext ( ) ) { Map . Entry < K , ValueEntry > valueEntry = it . next ( ) ; if ( valueEntry . getValue ( ) . count . get ( ) < least ) { least = valueEntry . getValue ( ) . count . get ( ) ; toBeRemovedByCount = valueEntry . getKey ( ) ; } if ( valueEntry . getValue ( ) . lastAccess . get ( ) < earliest ) { earliest = valueEntry . getValue ( ) . count . get ( ) ; toBeRemovedByTime = valueEntry . getKey ( ) ; } } if ( least > MINI_ACCESS ) { map . remove ( toBeRemovedByTime ) ; } else { map . remove ( toBeRemovedByCount ) ; } }
移除最近最少访问