01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.index.rtree.cachefs;
17:
18: import java.util.LinkedHashMap;
19: import java.util.Map;
20: import java.util.logging.Level;
21: import java.util.logging.Logger;
22:
23: /**
24: * DOCUMENT ME!
25: *
26: * @author Tommaso Nolli
27: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/index/rtree/cachefs/NodeCache.java $
28: */
29: public class NodeCache extends LinkedHashMap {
30: private static final Logger LOGGER = org.geotools.util.logging.Logging
31: .getLogger("org.geotools.index.rtree");
32: private final int maxElements;
33:
34: /**
35: * Constructor
36: */
37: public NodeCache() {
38: this (100);
39: }
40:
41: /**
42: * Constructor
43: *
44: * @param capacity the capacity of the cache
45: */
46: public NodeCache(int capacity) {
47: super (capacity);
48: this .maxElements = capacity;
49: }
50:
51: protected boolean removeEldestEntry(Map.Entry eldest) {
52: boolean ret = this .size() > this .maxElements;
53:
54: if (ret) {
55: try {
56: ((FileSystemNode) eldest.getValue()).flush();
57: } catch (Exception e) {
58: LOGGER.log(Level.SEVERE, e.getMessage(), e);
59: }
60: }
61:
62: return ret;
63: }
64: }
|