01: //##header
02: /*
03: * *****************************************************************************
04: * Copyright (C) 2006, International Business Machines Corporation and others.
05: * All Rights Reserved.
06: * *****************************************************************************
07: */
08: package com.ibm.icu.impl;
09:
10: //#ifndef FOUNDATION
11: import java.util.LinkedHashMap; //#endif
12: import java.util.Map;
13:
14: /*
15: * Simple LRU (Least Recent Used) Map implementation
16: */
17: public class LRUMap extends LinkedHashMap {
18: private static final long serialVersionUID = -8178106459089682120L;
19:
20: private static final int DEFAULT_MAXCAPACITY = 64;
21: private static final int DEFAULT_INITIALCAPACITY = 16;
22: private static final float DEFAULT_LOADFACTOR = 0.75F;
23:
24: private final int maxCapacity;
25:
26: /**
27: * Construct a new LRU map with the default initial
28: * capacity(16) and the maximum capacity(64).
29: */
30: public LRUMap() {
31: super (DEFAULT_INITIALCAPACITY, DEFAULT_LOADFACTOR, true);
32: maxCapacity = DEFAULT_MAXCAPACITY;
33: }
34:
35: /**
36: * Construct a new LRU map with the specified initial
37: * capacity and the maximum capacity
38: *
39: * @param initialCapacity initial capacity of the map
40: * @param maxCapacity maximum capacity of the map
41: */
42: public LRUMap(int initialCapacity, int maxCapacity) {
43: super (initialCapacity, DEFAULT_LOADFACTOR, true);
44: this .maxCapacity = maxCapacity;
45: }
46:
47: /*
48: * Delete the eldest entry when the size exceeds the limit
49: */
50: protected boolean removeEldestEntry(Map.Entry eldest) {
51: return (size() > maxCapacity);
52: }
53: }
|