Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Node.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 package org.openmobileis.database.fastobjectdb.db.index.node;
00030 
00031 import java.io.*;
00032 
00039 public abstract class Node implements Externalizable {
00040   // serialization constant
00041   static final long serialVersionUID = 5521257935120563452L;
00042   public final static long NO_NODE = -1;
00043 
00044   //-------------------------
00045   // fields
00046   //-------------------------
00047   public long filePtr = Node.NO_NODE; // location in page file
00048   public long parentPtr = Node.NO_NODE; // parent in page file
00049   public long[] ptr; // record pointers
00050   public long[] branchs; // links to other pages
00051   public int nbKey;
00052 
00053   //-------------------------
00054   // constructors
00055   //-------------------------
00056   public Node() {
00057     nbKey = 0;
00058   }
00059 
00060   public Node(int order) {
00061     this();
00062     ptr = new long[order - 1];
00063     branchs = new long[order];
00064 
00065     // fill arrays with empty values
00066     for (int n = 0; n < branchs.length; ++n)
00067       branchs[n] = Node.NO_NODE;
00068   }
00069 
00070   public long getNodePtrAtPos(int pos) {
00071     return this.ptr[pos];
00072   }
00073 
00074   public int getMaxNbKey() {
00075     return ptr.length;
00076   }
00077 
00078   //---------------------
00079   // serialization
00080   //---------------------
00081   public void writeExternal(ObjectOutput out) throws IOException {
00082     // write order and key length
00083     out.writeLong(filePtr);
00084     out.writeLong(parentPtr);
00085 
00086     // write pointers and links
00087                 this.serializeLongArray(out,ptr);
00088                 this.serializeLongArray(out,branchs);
00089     out.writeInt(nbKey);
00090   }
00091   
00092         protected void serializeLongArray(ObjectOutput out, long[] array) throws IOException {
00093                 int size=array.length;
00094                 out.writeInt(size);
00095                 for (int i=0; i<size; i++)      {
00096                         out.writeLong(array[i]);
00097                 }
00098   
00099         }
00100   
00101         protected long[] unserializeLongArray(ObjectInput in) throws IOException {
00102                 int size=in.readInt();
00103                 long[] ret = new long[size];
00104                 for (int i=0; i<size; i++)      {
00105                         ret[i] = in.readLong();
00106                 }
00107         return ret;
00108         }
00109   
00110         protected void serializeInArray(ObjectOutput out, int[] array) throws IOException {
00111                 int size=array.length;
00112                 out.writeInt(size);
00113                 for (int i=0; i<size; i++)      {
00114                         out.writeInt(array[i]);
00115                 }
00116   
00117         }
00118   
00119         protected int[] unserializeInArray(ObjectInput in) throws IOException {
00120                 int size=in.readInt();
00121                 int[] ret = new int[size];
00122                 for (int i=0; i<size; i++)      {
00123                         ret[i] = in.readInt();
00124                 }
00125                 return ret;
00126         }
00127 
00128   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
00129     filePtr = in.readLong();
00130     parentPtr = in.readLong();
00131     ptr = this.unserializeLongArray(in);
00132     branchs = this.unserializeLongArray(in);
00133     nbKey = in.readInt();
00134   }
00135 
00136 }

Generated on Wed Dec 14 21:05:34 2005 for OpenMobileIS by  doxygen 1.4.4