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