001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/rtree/MemoryPageFile.java $ 002 // 003 //RTree implementation. 004 //Copyright (C) 2002-2004 Wolfgang Baer - WBaer@gmx.de 005 // 006 //This library is free software; you can redistribute it and/or 007 //modify it under the terms of the GNU Lesser General Public 008 //License as published by the Free Software Foundation; either 009 //version 2.1 of the License, or (at your option) any later version. 010 // 011 //This library is distributed in the hope that it will be useful, 012 //but WITHOUT ANY WARRANTY; without even the implied warranty of 013 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 //Lesser General Public License for more details. 015 // 016 //You should have received a copy of the GNU Lesser General Public 017 //License along with this library; if not, write to the Free Software 018 //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 019 020 package org.deegree.io.rtree; 021 022 import java.io.Serializable; 023 import java.util.Hashtable; 024 025 /** 026 * <p> 027 * A memory based implementation of a PageFile.<br> 028 * Implemented as a Hashtable with keys representing the page file numbers of the saved nodes. 029 * </p> 030 * 031 * @author Wolfgang Baer - WBaer@gmx.de 032 */ 033 class MemoryPageFile extends PageFile implements Serializable { 034 035 private Hashtable<Integer, Node> file = new Hashtable<Integer, Node>( 500 ); 036 037 /** 038 * Constructor 039 */ 040 protected MemoryPageFile() { 041 super(); 042 file.clear(); 043 } 044 045 /** 046 * @see PageFile#readNode(int) 047 */ 048 protected Node readNode( int pageFile ) 049 throws PageFileException { 050 return file.get( new Integer( pageFile ) ); 051 } 052 053 /** 054 * @see PageFile#writeNode(Node) 055 */ 056 protected int writeNode( Node node ) 057 throws PageFileException { 058 059 int i = 0; 060 if ( node.getPageNumber() < 0 ) { 061 while ( true ) { 062 if ( !file.containsKey( new Integer( i ) ) ) { 063 break; 064 } 065 i++; 066 } 067 node.setPageNumber( i ); 068 } else 069 i = node.getPageNumber(); 070 071 file.put( new Integer( i ), node ); 072 073 return i; 074 } 075 076 /** 077 * @see PageFile#deleteNode(int) 078 */ 079 protected Node deleteNode( int pageNumber ) { 080 return file.remove( new Integer( pageNumber ) ); 081 } 082 083 /** 084 * @see PageFile#close() 085 */ 086 protected void close() 087 throws PageFileException { 088 // nothing to do 089 } 090 }