01: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/io/rtree/MemoryPageFile.java $
02: //
03: //RTree implementation.
04: //Copyright (C) 2002-2004 Wolfgang Baer - WBaer@gmx.de
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; either
09: //version 2.1 of the License, or (at your option) any later version.
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: //You should have received a copy of the GNU Lesser General Public
17: //License along with this library; if not, write to the Free Software
18: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19:
20: package org.deegree.io.rtree;
21:
22: import java.io.Serializable;
23: import java.util.Hashtable;
24:
25: /**
26: * <p>
27: * A memory based implementation of a PageFile.<br>
28: * Implemented as a Hashtable with keys representing the page file numbers of the saved nodes.
29: * </p>
30: *
31: * @author Wolfgang Baer - WBaer@gmx.de
32: */
33: class MemoryPageFile extends PageFile implements Serializable {
34:
35: private Hashtable<Integer, Node> file = new Hashtable<Integer, Node>(
36: 500);
37:
38: /**
39: * Constructor
40: */
41: protected MemoryPageFile() {
42: super ();
43: file.clear();
44: }
45:
46: /**
47: * @see PageFile#readNode(int)
48: */
49: protected Node readNode(int pageFile) throws PageFileException {
50: return file.get(new Integer(pageFile));
51: }
52:
53: /**
54: * @see PageFile#writeNode(Node)
55: */
56: protected int writeNode(Node node) throws PageFileException {
57:
58: int i = 0;
59: if (node.getPageNumber() < 0) {
60: while (true) {
61: if (!file.containsKey(new Integer(i))) {
62: break;
63: }
64: i++;
65: }
66: node.setPageNumber(i);
67: } else
68: i = node.getPageNumber();
69:
70: file.put(new Integer(i), node);
71:
72: return i;
73: }
74:
75: /**
76: * @see PageFile#deleteNode(int)
77: */
78: protected Node deleteNode(int pageNumber) {
79: return file.remove(new Integer(pageNumber));
80: }
81:
82: /**
83: * @see PageFile#close()
84: */
85: protected void close() throws PageFileException {
86: // nothing to do
87: }
88: }
|