KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > btree > Node


1 /*
2  * Node.java
3  *
4  * Created on 09 May 2003, 15:08
5  */

6
7 package com.jofti.btree;
8
9 import com.jofti.oswego.concurrent.FIFOReadWriteLock;
10 import com.jofti.oswego.concurrent.ReadWriteLock;
11
12
13
14
15
16 /**
17  * <p>Base class for Node providing the {@link ReadWriteLock} used in each Node to provide locking semantics.</p>
18  *
19  * @author steve Woodcock
20  * @version 1.15
21  *
22  */

23 abstract public class Node implements INode{
24     
25      public final ReadWriteLock nodeLock = new FIFOReadWriteLock();
26
27      protected int entryNumber = 0;
28   
29     
30     protected Object JavaDoc[] split(Object JavaDoc[] tempEntries, int entryNumber) {
31         // first insert the entry
32
Object JavaDoc[] entriesList = new Object JavaDoc[2];
33                         
34             // redistribute over old and new node
35

36             int splitPoint = (entryNumber / 2);
37             
38             Object JavaDoc[] newSplitValues = new Object JavaDoc[BTree.getMaxNodeSize()];
39
40
41             int endPoint = entryNumber - splitPoint;
42             // copies the split values into the new array
43
System.arraycopy(tempEntries,splitPoint,newSplitValues,0,endPoint);
44             
45             EntrySplitWrapper splitWrapper = new EntrySplitWrapper();
46             splitWrapper.size = endPoint;
47             splitWrapper.entries = newSplitValues;
48             
49             // remove the higher ones
50
for(int i=splitPoint;i<entryNumber;i++){
51                 tempEntries[i]=null;
52             }
53             
54             EntrySplitWrapper replacementWrapper = new EntrySplitWrapper();
55             replacementWrapper.size = splitPoint;
56             replacementWrapper.entries = tempEntries;
57                         
58             
59             
60             entriesList[0] =replacementWrapper;
61             entriesList[1]=splitWrapper;
62             return entriesList;
63     
64     }
65
66    
67     
68     /* (non-Javadoc)
69      * @see com.jofti.btree.INode#getNodeLock()
70      */

71     public ReadWriteLock getNodeLock()
72     {
73         return nodeLock;
74     }
75     
76     /* (non-Javadoc)
77      * @see com.jofti.btree.INode#isLeaf()
78      */

79     public boolean isLeaf(){
80         return false;
81     }
82
83 }
84
Popular Tags