001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2002, Centre for Computational Geography
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.index.rtree.memory;
018:
019: import org.geotools.index.DataDefinition;
020: import org.geotools.index.LockManager;
021: import org.geotools.index.TreeException;
022: import org.geotools.index.rtree.Entry;
023: import org.geotools.index.rtree.Node;
024: import org.geotools.index.rtree.PageStore;
025:
026: /**
027: * DOCUMENT ME!
028: *
029: * @author Tommaso Nolli
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/index/rtree/memory/MemoryPageStore.java $
031: */
032: public class MemoryPageStore extends PageStore {
033: private static final int DEF_MAX = 50;
034: private static final int DEF_MIN = 25;
035: private static final short DEF_SPLIT = SPLIT_QUADRATIC;
036: private LockManager lockManager = new LockManager();
037: private Node root = null;
038:
039: public MemoryPageStore(DataDefinition def) throws TreeException {
040: this (def, DEF_MAX, DEF_MIN, DEF_SPLIT);
041: }
042:
043: public MemoryPageStore(DataDefinition def, int max, int min,
044: short split) throws TreeException {
045: super (def, max, min, split);
046:
047: this .root = new MemoryNode(max);
048: this .root.setLeaf(true);
049: }
050:
051: /**
052: * @see org.geotools.index.rtree.PageStore#getRoot()
053: */
054: public Node getRoot() {
055: return this .root;
056: }
057:
058: /**
059: * @see org.geotools.index.rtree.PageStore#setRoot(org.geotools.index.rtree.Node)
060: */
061: public void setRoot(Node node) throws TreeException {
062: this .root = node;
063: this .root.setParent(null);
064: }
065:
066: /**
067: * @see org.geotools.index.rtree.PageStore#getEmptyNode(boolean)
068: */
069: public Node getEmptyNode(boolean isLeaf) {
070: MemoryNode ret = new MemoryNode(this .maxNodeEntries);
071: ret.setLeaf(isLeaf);
072:
073: return ret;
074: }
075:
076: /**
077: * @see org.geotools.index.rtree.PageStore#getNode(org.geotools.index.rtree.Entry,
078: * org.geotools.index.rtree.Node)
079: */
080: public Node getNode(Entry parentEntry, Node parent)
081: throws TreeException {
082: Node ret = (Node) parentEntry.getData();
083: ret.setParent(parent);
084:
085: return ret;
086: }
087:
088: /**
089: * @see org.geotools.index.rtree.PageStore#createEntryPointingNode(org.geotools.index.rtree.Node)
090: */
091: public Entry createEntryPointingNode(Node node) {
092: return new Entry(node.getBounds(), node);
093: }
094:
095: /**
096: * @see org.geotools.index.rtree.PageStore#free(org.geotools.index.rtree.Node)
097: */
098: public void free(Node node) {
099: // Does nothing
100: }
101:
102: /**
103: * @see org.geotools.index.rtree.PageStore#close()
104: */
105: public void close() throws TreeException {
106: this.root = null;
107: }
108: }
|