001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/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: * <p>
026: * Implementation of a LeafNode.
027: * Inherits methods from the abstract class Node filling
028: * the defined abstract methods with life.
029: * </p>
030: * @author Wolfgang Baer - WBaer@gmx.de
031: */
032: class LeafNode extends Node implements Serializable {
033:
034: protected int[] data;
035:
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
090: .getDimension());
091: data[0] = -1;
092: } else {
093: System.arraycopy(hyperBBs, index + 1, hyperBBs, index,
094: counter - index - 1);
095: System.arraycopy(data, index + 1, data, index, counter
096: - index - 1);
097: hyperBBs[counter - 1] = HyperBoundingBox
098: .getNullHyperBoundingBox(file.getDimension());
099: data[counter - 1] = -1;
100: }
101:
102: counter--;
103: updateNodeBoundingBox();
104: }
105:
106: /**
107: * @see Node#clone()
108: */
109: protected Object clone() {
110:
111: LeafNode clone = new LeafNode(this .pageNumber, this .file);
112: clone.counter = this .counter;
113: clone.place = this .place;
114: clone.unionMinBB = (HyperBoundingBox) this .unionMinBB.clone();
115: clone.parentNode = this .parentNode;
116:
117: for (int i = 0; i < file.getCapacity(); i++)
118: clone.hyperBBs[i] = (HyperBoundingBox) this.hyperBBs[i]
119: .clone();
120:
121: return clone;
122: }
123: }
|