01: //
02: // This file is part of the prose package.
03: //
04: // The contents of this file are subject to the Mozilla Public License
05: // Version 1.1 (the "License"); you may not use this file except in
06: // compliance with the License. You may obtain a copy of the License at
07: // http://www.mozilla.org/MPL/
08: //
09: // Software distributed under the License is distributed on an "AS IS" basis,
10: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11: // for the specific language governing rights and limitations under the
12: // License.
13: //
14: // The Original Code is prose.
15: //
16: // The Initial Developer of the Original Code is Andrei Popovici. Portions
17: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18: // All Rights Reserved.
19: //
20: // Contributor(s):
21: // $Id$
22: // =====================================================================
23: //
24: // (history at end)
25: //
26:
27: package ch.ethz.inf.iks.jvmai.jvmdi;
28:
29: import java.util.LinkedHashMap;
30: import java.util.Map;
31:
32: /**
33: * Simple LinkedHashMap based object cache implementation.
34: * If the number of entries reaches a specified size,
35: * insertion of a new entry will also remove the oldest entry
36: * from the cache.
37: *
38: * @author Angela Nicoara
39: * @author Gerald Linhofer
40: * @version $Revision$
41: */
42: public class CacheMap extends LinkedHashMap {
43: /**
44: * Serial Version Unique Identifier
45: */
46: private static final long serialVersionUID = 3904676089644005689L;
47: private int maxSize;
48:
49: /**
50: * Creates a CacheMap instance.
51: *
52: * @param size capacity of the map.
53: */
54: public CacheMap(int size) {
55: super (size * 4 / 3 + 1);
56: maxSize = size;
57: }
58:
59: protected boolean removeEldestEntry(Map.Entry eldest) {
60: return maxSize < size();
61: }
62: }
63:
64: //======================================================================
65: //
66: // $Log$
67: //
|