KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > ix > IxTree


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.inside.ix;
22
23 import com.db4o.*;
24 import com.db4o.foundation.*;
25 import com.db4o.inside.freespace.*;
26
27 /**
28  * @exclude
29  */

30 public abstract class IxTree extends Tree implements Visitor4{
31     
32     IndexTransaction _fieldTransaction;
33     
34     int _version;
35     
36     int _nodes = 1;
37     
38     IxTree(IndexTransaction a_ft){
39         _fieldTransaction = a_ft;
40         _version = a_ft.i_version;
41     }
42     
43     public Tree add(final Tree a_new, final int a_cmp){
44         if(a_cmp < 0){
45             if(_subsequent == null){
46                 _subsequent = a_new;
47             }else{
48                 _subsequent = _subsequent.add(a_new);
49             }
50         }else {
51             if(_preceding == null){
52                 _preceding = a_new;
53             }else{
54                 _preceding = _preceding.add(a_new);
55             }
56         }
57         return balanceCheckNulls();
58     }
59     
60     void beginMerge(){
61         _preceding = null;
62         _subsequent = null;
63         setSizeOwn();
64     }
65     
66     public Object JavaDoc deepClone(Object JavaDoc a_param) {
67         IxTree tree = (IxTree) this.shallowClone();
68         tree._fieldTransaction = (IndexTransaction) a_param;
69         tree._nodes = _nodes;
70         return tree;
71     }
72     
73     final Indexable4 handler(){
74         return _fieldTransaction.i_index._handler;
75     }
76     
77     final Index4 index(){
78         return _fieldTransaction.i_index;
79     }
80     
81     /**
82      * Overridden in IxFileRange
83      * Only call directly after compare()
84      */

85     int[] lowerAndUpperMatch(){
86         return null;
87     }
88     
89     public final int nodes(){
90         return _nodes;
91     }
92     
93     public void setSizeOwn(){
94         super.setSizeOwn();
95         _nodes = 1;
96     }
97     
98     public void setSizeOwnPrecedingSubsequent(){
99         super.setSizeOwnPrecedingSubsequent();
100         _nodes = 1 + _preceding.nodes() + _subsequent.nodes();
101     }
102     
103     public void setSizeOwnPreceding(){
104         super.setSizeOwnPreceding();
105         _nodes = 1 + _preceding.nodes();
106     }
107     
108     public void setSizeOwnSubsequent(){
109         super.setSizeOwnSubsequent();
110         _nodes = 1 + _subsequent.nodes();
111     }
112     
113     public final void setSizeOwnPlus(Tree tree){
114         super.setSizeOwnPlus(tree);
115         _nodes = 1 + tree.nodes();
116     }
117     
118     public final void setSizeOwnPlus(Tree tree1, Tree tree2){
119         super.setSizeOwnPlus(tree1, tree2);
120         _nodes = 1 + tree1.nodes() + tree2.nodes();
121     }
122     
123     int slotLength(){
124         return handler().linkLength() + YapConst.INT_LENGTH;
125     }
126     
127     final YapFile stream(){
128         return trans().i_file;
129     }
130     
131     final Transaction trans(){
132         return _fieldTransaction.i_trans;
133     }
134     
135     public abstract void visit(Object JavaDoc obj);
136     
137     public abstract void visit(Visitor4 visitor, int[] a_lowerAndUpperMatch);
138     
139     public abstract void visitAll(IntObjectVisitor visitor);
140     
141     public abstract void freespaceVisit(FreespaceVisitor visitor, int index);
142     
143     public abstract int write(Indexable4 a_handler, YapWriter a_writer);
144     
145     public void visitFirst(FreespaceVisitor visitor){
146         if(_preceding != null){
147             ((IxTree)_preceding).visitFirst(visitor);
148             if(visitor.visited()){
149                 return;
150             }
151         }
152         freespaceVisit(visitor, 0);
153         if(visitor.visited()){
154             return;
155         }
156         if(_subsequent != null){
157             ((IxTree)_subsequent).visitFirst(visitor);
158             if(visitor.visited()){
159                 return;
160             }
161         }
162     }
163     
164     public void visitLast(FreespaceVisitor visitor){
165         if(_subsequent != null){
166             ((IxTree)_subsequent).visitLast(visitor);
167             if(visitor.visited()){
168                 return;
169             }
170         }
171         freespaceVisit(visitor, 0);
172         if(visitor.visited()){
173             return;
174         }
175         if(_preceding != null){
176             ((IxTree)_preceding).visitLast(visitor);
177             if(visitor.visited()){
178                 return;
179             }
180         }
181     }
182     
183     protected Tree shallowCloneInternal(Tree tree) {
184         IxTree ixTree=(IxTree)super.shallowCloneInternal(tree);
185         ixTree._fieldTransaction=_fieldTransaction;
186         ixTree._version=_version;
187         ixTree._nodes=_nodes;
188         return ixTree;
189     }
190     
191     public Object JavaDoc key(){
192         throw new NotImplementedException();
193     }
194 }
195
Popular Tags