1 18 package org.apache.activemq.memory; 19 20 import java.util.LinkedHashMap ; 21 import java.util.Map ; 22 23 28 public class LRUMap extends LinkedHashMap { 29 private static final long serialVersionUID = -9179676638408888162L; 30 31 protected static final float DEFAULT_LOAD_FACTOR = (float) 0.75; 32 protected static final int DEFAULT_INITIAL_CAPACITY = 5000; 33 34 private int maximumSize; 35 36 public LRUMap(int maximumSize) { 37 this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, true, maximumSize); 38 } 39 40 public LRUMap(int maximumSize, boolean accessOrder) { 41 this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, accessOrder, maximumSize); 42 } 43 44 public LRUMap(int initialCapacity, float loadFactor, boolean accessOrder, int maximumSize) { 45 super(initialCapacity, loadFactor, accessOrder); 46 this.maximumSize = maximumSize; 47 } 48 49 protected boolean removeEldestEntry(Map.Entry eldest) { 50 return size() > maximumSize; 51 } 52 } 53 | Popular Tags |