001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/rtree/Node.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 024 /** 025 * <p> 026 * Abstract class for common implementation and definition of abstract methods for both concrete 027 * classes LeafNode and NoneLeafNode. 028 * </p> 029 * 030 * @author Wolfgang Baer - WBaer@gmx.de 031 * @author last edited by: $Author: apoth $ 032 * 033 * @version $Revision: 9342 $, $Date: 2007-12-27 13:32:57 +0100 (Do, 27 Dez 2007) $ 034 */ 035 abstract class Node implements Serializable { 036 037 protected transient PageFile file; 038 039 protected int parentNode; 040 041 protected int pageNumber; 042 043 protected int counter; 044 045 protected HyperBoundingBox unionMinBB; 046 047 protected HyperBoundingBox[] hyperBBs; 048 049 protected int place; 050 051 /** 052 * Constructor. 053 * 054 * @param pageNumber - 055 * number of this node in page file 056 * @param pageFile - 057 * the PageFile of this node 058 */ 059 protected Node( int pageNumber, PageFile pageFile ) { 060 this.file = pageFile; 061 this.pageNumber = pageNumber; 062 parentNode = 0; 063 hyperBBs = new HyperBoundingBox[file.getCapacity()]; 064 065 for ( int i = 0; i < file.getCapacity(); i++ ) 066 hyperBBs[i] = HyperBoundingBox.getNullHyperBoundingBox( file.getDimension() ); 067 068 unionMinBB = HyperBoundingBox.getNullHyperBoundingBox( file.getDimension() ); 069 counter = 0; 070 } 071 072 /** 073 * Inserts the given data into the node 074 * 075 * @param obj - 076 * object to insert (Typ Integer oder AbstractNode) 077 * @param box - 078 * the associated HyperBoundingBox 079 */ 080 protected abstract void insertData( Object obj, HyperBoundingBox box ); 081 082 /** 083 * Deletes a the entry with given index from node 084 * 085 * @param index - 086 * index of entry 087 */ 088 protected abstract void deleteData( int index ); 089 090 /** 091 * Fetches the data for given index from node 092 * 093 * @param index - 094 * index of data 095 * @return 096 */ 097 protected abstract Object getData( int index ); 098 099 /** 100 * Returns the parent node of this. 101 * 102 * @return Node 103 */ 104 protected Node getParent() { 105 106 Node node = null; 107 try { 108 node = file.readNode( parentNode ); 109 } catch ( PageFileException e ) { 110 // PageFileException: AbstractNode.getParent() - readNode 111 e.printStackTrace(); 112 } 113 114 return node; 115 } 116 117 /** 118 * Returns the page number of this. 119 * 120 * @return int 121 */ 122 protected int getPageNumber() { 123 return pageNumber; 124 } 125 126 /** 127 * Sets the page number of this to given number 128 * 129 * @param number - 130 * int 131 */ 132 protected void setPageNumber( int number ) { 133 this.pageNumber = number; 134 } 135 136 /** 137 * Currently used space in the node 138 * 139 * @return int 140 */ 141 protected int getUsedSpace() { 142 return counter; 143 } 144 145 /** 146 * Returns the HyperBoundingBox over all Entries currently in the node 147 * 148 * @return HyperBoundingBox 149 */ 150 protected HyperBoundingBox getUnionMinBB() { 151 return unionMinBB; 152 } 153 154 /** 155 * Updates the HyperBoundingBox over all Entries currently in the node 156 */ 157 protected void updateNodeBoundingBox() { 158 this.unionMinBB = HyperBoundingBox.getNullHyperBoundingBox( file.getDimension() ); 159 ; 160 for ( int i = 0; i < this.getUsedSpace(); i++ ) 161 this.unionMinBB = this.unionMinBB.unionBoundingBox( this.hyperBBs[i] ); 162 } 163 164 /** 165 * Returns an array of HyperBoundingBox objects of the entries of the node. The array may be 166 * empty - for used place in the node see getUsedSpace. 167 * 168 * @return HyperBoundingBox[] - boxes of the entries 169 * @see #getUsedSpace() 170 */ 171 protected HyperBoundingBox[] getHyperBoundingBoxes() { 172 return hyperBBs; 173 } 174 175 /** 176 * Returns the HyperBoundingBox for entrie with given index. 177 * 178 * @param index - 179 * index of entry 180 * @return HyperBoundingBox 181 */ 182 protected HyperBoundingBox getHyperBoundingBox( int index ) { 183 return hyperBBs[index]; 184 } 185 186 /** 187 * Tests if this is the root node. 188 * 189 * @return boolean 190 */ 191 protected boolean isRoot() { 192 return pageNumber == 0; 193 } 194 195 /** 196 * Deep copy without data entries (only HyperBoundingBox objects) 197 * 198 * @see java.lang.Object#clone() 199 */ 200 protected abstract Object clone(); 201 202 /** 203 * String-Representation of Node 204 * 205 * @return 206 */ 207 public String toString() { 208 String str = ""; 209 210 if ( this instanceof LeafNode ) { 211 str = "LeafNode: " + unionMinBB.toString(); 212 } else { 213 str = "NoneLeafNode: " + unionMinBB.toString(); 214 } 215 216 return str; 217 } 218 }