KickJava   Java API By Example, From Geeks To Geeks.

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


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.foundation.*;
24
25 /**
26  * Node for index tree, can be addition or removal node
27  */

28 public abstract class IxPatch extends IxTree {
29
30     int _parentID;
31
32     Object JavaDoc _value;
33
34     private Queue4 _queue; // queue of patch objects for the same parent
35

36     IxPatch(IndexTransaction a_ft, int a_parentID, Object JavaDoc a_value) {
37         super(a_ft);
38         _parentID = a_parentID;
39         _value = a_value;
40     }
41
42     public Tree add(final Tree a_new) {
43         int cmp = compare(a_new);
44         if (cmp == 0) {
45             IxPatch patch = (IxPatch) a_new;
46             cmp = _parentID - patch._parentID;
47
48             if (cmp == 0) {
49
50                 Queue4 queue = _queue;
51
52                 if (queue == null) {
53                     queue = new Queue4();
54                     queue.add(this);
55                 }
56
57                 queue.add(patch);
58                 patch._queue = queue;
59                 patch._subsequent = _subsequent;
60                 patch._preceding = _preceding;
61                 patch.calculateSize();
62                 return patch;
63             }
64         }
65         return add(a_new, cmp);
66     }
67
68     public int compare(Tree a_to) {
69         Indexable4 handler = _fieldTransaction.i_index._handler;
70         return handler.compareTo(handler.comparableObject(trans(), _value));
71     }
72     
73     public boolean hasQueue() {
74         return _queue != null;
75     }
76
77     public Queue4 detachQueue() {
78         Queue4 queue = _queue;
79         this._queue = null;
80         return queue;
81     }
82
83     protected Tree shallowCloneInternal(Tree tree) {
84         IxPatch patch=(IxPatch)super.shallowCloneInternal(tree);
85         patch._parentID=_parentID;
86         patch._value=_value;
87         patch._queue=_queue;
88         return patch;
89     }
90 }
91
Popular Tags