KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > freespace > FreespaceIx


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.freespace;
22
23 import com.db4o.*;
24 import com.db4o.foundation.*;
25 import com.db4o.inside.ix.*;
26
27
28 abstract class FreespaceIx {
29     
30     Index4 _index;
31     
32     IndexTransaction _indexTrans;
33     
34     IxTraverser _traverser;
35     
36     FreespaceVisitor _visitor;
37     
38     FreespaceIx(YapFile file, MetaIndex metaIndex){
39         _index = new Index4(file.getSystemTransaction(),new YInt(file), metaIndex, false);
40         _indexTrans = _index.globalIndexTransaction();
41     }
42     
43     abstract void add(int address, int length);
44     
45     abstract int address();
46     
47     public void debug(){
48         if(Debug.freespace){
49             traverse(new Visitor4(){
50                 public void visit(Object JavaDoc obj) {
51                     System.out.println(obj);
52                 }
53             });
54         }
55     }
56     
57     public int entryCount() {
58         return Tree.size(_indexTrans.getRoot());
59     }
60     
61     void find (int val){
62         _traverser = new IxTraverser();
63         _traverser.findBoundsExactMatch(new Integer JavaDoc(val), (IxTree)_indexTrans.getRoot());
64     }
65     
66     abstract int length();
67     
68     boolean match(){
69         _visitor = new FreespaceVisitor();
70         _traverser.visitMatch(_visitor);
71         return _visitor.visited();
72     }
73     
74     boolean preceding(){
75         _visitor = new FreespaceVisitor();
76         _traverser.visitPreceding(_visitor);
77         return _visitor.visited();
78     }
79     
80     abstract void remove(int address, int length);
81     
82     boolean subsequent(){
83         _visitor = new FreespaceVisitor();
84         _traverser.visitSubsequent(_visitor);
85         return _visitor.visited();
86     }
87     
88     public void traverse(Visitor4 visitor){
89         Tree.traverse(_indexTrans.getRoot(), visitor);
90     }
91     
92
93 }
94
Popular Tags