KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > impl > LRUMap


1 //##header 1189099963000 FOUNDATION
2
/*
3  * *****************************************************************************
4  * Copyright (C) 2006, International Business Machines Corporation and others.
5  * All Rights Reserved.
6  * *****************************************************************************
7  */

8 package com.ibm.icu.impl;
9
10 //#ifndef FOUNDATION
11
//##import java.util.LinkedHashMap;
12
//#endif
13
import java.util.Map JavaDoc;
14
15 /*
16  * Simple LRU (Least Recent Used) Map implementation
17  */

18 public class LRUMap extends LinkedHashMap {
19     private static final long serialVersionUID = -8178106459089682120L;
20
21     private static final int DEFAULT_MAXCAPACITY = 64;
22     private static final int DEFAULT_INITIALCAPACITY = 16;
23     private static final float DEFAULT_LOADFACTOR = 0.75F;
24
25     private final int maxCapacity;
26
27     /**
28      * Construct a new LRU map with the default initial
29      * capacity(16) and the maximum capacity(64).
30      */

31     public LRUMap() {
32         super(DEFAULT_INITIALCAPACITY, DEFAULT_LOADFACTOR, true);
33         maxCapacity = DEFAULT_MAXCAPACITY;
34     }
35
36     /**
37      * Construct a new LRU map with the specified initial
38      * capacity and the maximum capacity
39      *
40      * @param initialCapacity initial capacity of the map
41      * @param maxCapacity maximum capacity of the map
42      */

43     public LRUMap(int initialCapacity, int maxCapacity) {
44         super(initialCapacity, DEFAULT_LOADFACTOR, true);
45         this.maxCapacity = maxCapacity;
46     }
47
48     /*
49      * Delete the eldest entry when the size exceeds the limit
50      */

51     protected boolean removeEldestEntry(Map.Entry JavaDoc eldest) {
52         return (size() > maxCapacity);
53     }
54 }
55
Popular Tags