Coverage Report - org.apache.camel.util.LRUCache
 
Classes in this File Line Coverage Branch Coverage Complexity
LRUCache
88% 
100% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.util;
 19  
 
 20  
 import java.util.LinkedHashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 /**
 24  
  * A Least Recently Used Cache
 25  
  *
 26  
  * @version $Revision: 1.1 $
 27  
  */
 28  
 public class LRUCache<K, V> extends LinkedHashMap<K, V> {
 29  
     private static final long serialVersionUID = -342098639681884413L;
 30  2
     private int maxCacheSize = 10000;
 31  
 
 32  
     public LRUCache(int maximumCacheSize) {
 33  2
         this(maximumCacheSize, maximumCacheSize, 0.75f, true);
 34  2
     }
 35  
 
 36  
     /**
 37  
      * Constructs an empty <tt>LRUCache</tt> instance with the
 38  
      * specified initial capacity, maximumCacheSize,load factor and ordering mode.
 39  
      *
 40  
      * @param initialCapacity  the initial capacity.
 41  
      * @param maximumCacheSize
 42  
      * @param loadFactor       the load factor.
 43  
      * @param accessOrder      the ordering mode - <tt>true</tt> for
 44  
      *                         access-order, <tt>false</tt> for insertion-order.
 45  
      * @throws IllegalArgumentException if the initial capacity is negative
 46  
      *                                  or the load factor is nonpositive.
 47  
      */
 48  
     public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) {
 49  2
         super(initialCapacity, loadFactor, accessOrder);
 50  2
         this.maxCacheSize = maximumCacheSize;
 51  2
     }
 52  
 
 53  
     /**
 54  
      * @return Returns the maxCacheSize.
 55  
      */
 56  
     public int getMaxCacheSize() {
 57  0
         return maxCacheSize;
 58  
     }
 59  
 
 60  
     protected boolean removeEldestEntry(Map.Entry entry) {
 61  3
         return size() > maxCacheSize;
 62  
     }
 63  
 }