001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/rtree/LeafNode.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 /**
026 * <p>
027 * Implementation of a LeafNode.
028 * Inherits methods from the abstract class Node filling
029 * the defined abstract methods with life.
030 * </p>
031 * @author Wolfgang Baer - WBaer@gmx.de
032 */
033 class LeafNode extends Node implements Serializable {
034
035 protected int[] data;
036 //protected Object[] data;
037
038 /**
039 * Constructor.
040 * @param pageNumber - number of this node in page file
041 * @param file - the PageFile of this node
042 */
043 protected LeafNode( int pageNumber, PageFile file ) {
044 super( pageNumber, file );
045 data = new int[file.getCapacity()];
046
047 for ( int i = 0; i < file.getCapacity(); i++ )
048 data[i] = -1;
049 }
050
051 /**
052 * Constructor.<br>
053 * The page number in the pagefile will be
054 * assigned with the first save to a page file
055 * @param file - the PageFile of this node
056 */
057 protected LeafNode( PageFile file ) {
058 super( -1, file );
059 data = new int[file.getCapacity()];
060
061 for ( int i = 0; i < file.getCapacity(); i++ )
062 data[i] = -1;
063 }
064
065 /**
066 * Return type is an Integer object
067 * @see Node#getData(int)
068 */
069 protected Object getData( int index ) {
070 return new Integer( data[index] );
071 }
072
073 /**
074 * @see Node#insertData(java.lang.Object, HyperBoundingBox)
075 */
076 protected void insertData(Object obj, HyperBoundingBox box) {
077 data[counter] = ( (Integer)obj ).intValue();
078 hyperBBs[counter] = box;
079 unionMinBB = unionMinBB.unionBoundingBox( box );
080 counter = counter + 1;
081 }
082
083 /**
084 * @see Node#insertData(java.lang.Object, HyperBoundingBox)
085 */
086 protected void deleteData(int index) {
087 if ( this.getUsedSpace() == 1 ) {
088 // only one element is a special case.
089 hyperBBs[0] = HyperBoundingBox.getNullHyperBoundingBox( file.getDimension() );
090 data[0] = -1;
091 }
092 else {
093 System.arraycopy( hyperBBs, index + 1, hyperBBs, index, counter - index - 1 );
094 System.arraycopy( data, index + 1, data, index, counter - index - 1 );
095 hyperBBs[counter - 1] = HyperBoundingBox.getNullHyperBoundingBox( file.getDimension() );
096 data[counter - 1] = -1;
097 }
098
099 counter--;
100 updateNodeBoundingBox();
101 }
102
103 /**
104 * @see Node#clone()
105 */
106 protected Object clone() {
107
108 LeafNode clone = new LeafNode( this.pageNumber, this.file );
109 clone.counter = this.counter;
110 clone.place = this.place;
111 clone.unionMinBB = (HyperBoundingBox)this.unionMinBB.clone();
112 clone.parentNode = this.parentNode;
113
114 for ( int i = 0; i < file.getCapacity(); i++ )
115 clone.hyperBBs[i] = (HyperBoundingBox)this.hyperBBs[i].clone();
116
117 return clone;
118 }
119 }