KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > index > hash > HashEntry


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.hash;
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 DiskBased Hash Index
24  *
25  * @version $Revision: 1.1.1.1 $
26  */

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

64     Comparable JavaDoc getKey(){
65         return this.key;
66     }
67
68     /**
69      * @param key the key to set
70      */

71     void setKey(Comparable JavaDoc key){
72         this.key=key;
73     }
74
75     /**
76      * @return the indexOffset
77      */

78     long getIndexOffset(){
79         return this.indexOffset;
80     }
81
82     /**
83      * @param indexOffset the indexOffset to set
84      */

85     void setIndexOffset(long indexOffset){
86         this.indexOffset=indexOffset;
87     }
88
89     void write(Marshaller keyMarshaller,DataOutput JavaDoc dataOut) throws IOException JavaDoc{
90         dataOut.writeLong(indexOffset);
91         keyMarshaller.writePayload(key,dataOut);
92     }
93
94     void read(Marshaller keyMarshaller,DataInput JavaDoc dataIn) throws IOException JavaDoc{
95         indexOffset=dataIn.readLong();
96         key=(Comparable JavaDoc)keyMarshaller.readPayload(dataIn);
97     }
98 }
99
Popular Tags