1 /** 2 * Copyright 2010 The Kuali Foundation Licensed under the 3 * Educational Community License, Version 2.0 (the "License"); you may 4 * not use this file except in compliance with the License. You may 5 * obtain a copy of the License at 6 * 7 * http://www.osedu.org/licenses/ECL-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, 10 * software distributed under the License is distributed on an "AS IS" 11 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 * or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package org.kuali.student.common.util; 17 18 import java.util.LinkedHashMap; 19 import java.util.Map; 20 21 /** 22 * A <code>Map<code> implementation with a fixed maximum size of a 23 * least recently used (LRU) entry list using a <code>LinkedHashMap</code>. 24 * 25 * @param <K> Key 26 * @param <V> Value 27 */ 28 public class LRUMap<K,V> extends LinkedHashMap<K,V> { 29 /** Class serial version uid */ 30 private static final long serialVersionUID = 1L; 31 32 /** Maximum size of map */ 33 private int maxSize = 50; 34 35 /** 36 * Constructs a new LRU Map with a default maximum size of 50 entries. 37 */ 38 public LRUMap() { 39 } 40 41 /** 42 * Constructs a new LRU Map. 43 * 44 * @param maxSize Maximum size of LRU map. 45 */ 46 public LRUMap(int maxSize) { 47 this.maxSize = maxSize; 48 } 49 50 /** 51 * Removed oldest entry in map. 52 * 53 * @param eldest Oldest entry to remove 54 */ 55 public boolean removeEldestEntry(Map.Entry<K,V> eldest) { 56 return size() > this.maxSize; 57 } 58 }