KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > index > tree > TreeEntry


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
4  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
5  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12  * specific language governing permissions and limitations under the License.
13  */

14
15 package org.apache.activemq.kaha.impl.index.tree;
16
17 import java.io.DataInput JavaDoc;
18 import java.io.DataOutput JavaDoc;
19 import java.io.IOException JavaDoc;
20 import org.apache.activemq.kaha.Marshaller;
21
22 /**
23  * Key and index for a BTree
24  *
25  * @version $Revision: 1.1.1.1 $
26  */

27 class TreeEntry implements Comparable JavaDoc{
28
29     static final int NOT_SET=-1;
30     private Comparable JavaDoc key;
31     private long indexOffset;
32     private long prevPageId=NOT_SET;
33     private long nextPageId=NOT_SET;
34
35     public int compareTo(Object JavaDoc o){
36         if(o instanceof TreeEntry){
37             TreeEntry other=(TreeEntry)o;
38             return key.compareTo(other.key);
39         }else{
40             return key.compareTo(o);
41         }
42     }
43
44     public boolean equals(Object JavaDoc o){
45         return compareTo(o)==0;
46     }
47
48     public int hasCode(){
49         return key.hashCode();
50     }
51
52     public String JavaDoc toString(){
53         return "TreeEntry("+key+","+indexOffset+")prev="+prevPageId+",next="+nextPageId;
54     }
55
56     void reset(){
57         prevPageId=nextPageId=NOT_SET;
58     }
59
60     TreeEntry copy(){
61         TreeEntry copy=new TreeEntry();
62         copy.key=this.key;
63         copy.indexOffset=this.indexOffset;
64         copy.prevPageId=this.prevPageId;
65         copy.nextPageId=this.nextPageId;
66         return copy;
67     }
68
69     /**
70      * @return the key
71      */

72     Comparable JavaDoc getKey(){
73         return this.key;
74     }
75
76     /**
77      * @param key the key to set
78      */

79     void setKey(Comparable JavaDoc key){
80         this.key=key;
81     }
82
83     /**
84      * @return the nextPageId
85      */

86     long getNextPageId(){
87         return this.nextPageId;
88     }
89
90     /**
91      * @param nextPageId the nextPageId to set
92      */

93     void setNextPageId(long nextPageId){
94         this.nextPageId=nextPageId;
95     }
96
97     /**
98      * @return the prevPageId
99      */

100     long getPrevPageId(){
101         return this.prevPageId;
102     }
103
104     /**
105      * @param prevPageId the prevPageId to set
106      */

107     void setPrevPageId(long prevPageId){
108         this.prevPageId=prevPageId;
109     }
110     
111     /**
112      * @return the indexOffset
113      */

114      long getIndexOffset(){
115         return this.indexOffset;
116     }
117
118     
119     /**
120      * @param indexOffset the indexOffset to set
121      */

122      void setIndexOffset(long indexOffset){
123         this.indexOffset=indexOffset;
124     }
125
126     boolean hasChildPagesReferences(){
127         return prevPageId!=NOT_SET||nextPageId!=NOT_SET;
128     }
129
130     void write(Marshaller keyMarshaller,DataOutput JavaDoc dataOut) throws IOException JavaDoc{
131         keyMarshaller.writePayload(key,dataOut);
132         dataOut.writeLong(indexOffset);
133         dataOut.writeLong(nextPageId);
134         dataOut.writeLong(prevPageId);
135     }
136
137     void read(Marshaller keyMarshaller,DataInput JavaDoc dataIn) throws IOException JavaDoc{
138         key=(Comparable JavaDoc)keyMarshaller.readPayload(dataIn);
139         indexOffset=dataIn.readLong();
140         nextPageId=dataIn.readLong();
141         prevPageId=dataIn.readLong();
142     }
143
144     
145    
146 }
147
Popular Tags