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

FODBIndexTable.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;
00030 
00031 import java.io.*;
00032 
00033 import org.openmobileis.database.fastobjectdb.db.index.node.Node;
00034 
00035 
00040 public class FODBIndexTable implements Externalizable {
00041         private static int DEF_TAB_SIZE = 20;
00042         
00043         private int incTabSize;
00044         private int currentSize;
00045         
00046         private long[] indexsPos;
00047         
00048         public FODBIndexTable() {
00049                 incTabSize = DEF_TAB_SIZE;                              // default value;
00050                 constructorHelper();
00051         }
00052         
00053         public FODBIndexTable(int tSize) {
00054                 incTabSize = tSize;
00055                 constructorHelper();
00056         }
00057         
00058         protected void constructorHelper() {
00059                 currentSize = 0;
00060                 indexsPos = new long[incTabSize];
00061                 
00062                 for (int i = 0; i < incTabSize; i++) {
00063                         indexsPos[i] = Node.NO_NODE;
00064                 }
00065         }
00066         
00067         public int size() {
00068                 return currentSize;
00069         }
00070         
00071         public int allocatedSize() {
00072                 return indexsPos.length;
00073         }
00074         
00075         public synchronized boolean add(long pos) {
00076                 int tabSize = indexsPos.length;
00077                 
00078                 if (currentSize < tabSize) {
00079                         indexsPos[currentSize] = pos;
00080                         currentSize++;
00081                         return false;
00082                 }
00083                 else { // currentSize == tabSize
00084                         long[] newIndexsPos = new long[tabSize + incTabSize];
00085                         
00086                         System.arraycopy(indexsPos, 0, newIndexsPos, 0, indexsPos.length);
00087                         
00088                         newIndexsPos[currentSize] = pos;
00089                         
00090                         for (int i = currentSize+1; i<newIndexsPos.length; i++)  {
00091                                 newIndexsPos[i] = Node.NO_NODE;
00092                         }
00093                         
00094                         indexsPos = newIndexsPos;
00095                         currentSize++;
00096                         return true;
00097                 }
00098                 
00099         }
00100         
00101         public long getPosByPlace(int place) {
00102                 if (place >= currentSize || place < 0) {
00103                         return Node.NO_NODE;
00104                 }
00105                 return indexsPos[place];
00106         }
00107         
00108         public String toString() {
00109                 String result = "       FODBIndexTable[" + incTabSize + ", " + currentSize + "]\n";
00110                 
00111                 result = result.concat("         [");
00112                 for (int i = 0; i < currentSize; i++) {
00113                         result = result.concat("(" + indexsPos[i] + ")");
00114                 }
00115                 result = result.concat("]\n");
00116                 
00117                 return result;
00118         }
00119         
00120         public void writeExternal(ObjectOutput out) throws IOException {
00121                 out.writeInt(incTabSize);
00122                 out.writeInt(currentSize);
00123                 out.writeInt(indexsPos.length);
00124                 for (int i = 0; i < indexsPos.length; i++) {
00125                         out.writeLong(indexsPos[i]);
00126                 }
00127         }
00128         
00129         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
00130                 incTabSize = in.readInt();
00131                 currentSize = in.readInt();
00132                 int realTabSize = in.readInt();
00133                 
00134                 indexsPos = new long[realTabSize];
00135                 
00136                 for (int i = 0; i < realTabSize; i++) {
00137                         indexsPos[i] = in.readLong();
00138                 }
00139         }
00140 
00141 }
00142                 

Generated on Thu Oct 6 10:06:32 2005 for OpenMobileIS by  doxygen 1.4.3