1 14 15 package org.apache.activemq.kaha.impl.index.hash; 16 17 import java.io.DataInput ; 18 import java.io.DataOutput ; 19 import java.io.IOException ; 20 import org.apache.activemq.kaha.Marshaller; 21 22 27 class HashEntry implements Comparable { 28 29 static final int NOT_SET=-1; 30 private Comparable key; 31 private long indexOffset; 32 33 public int compareTo(Object 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 o){ 43 return compareTo(o)==0; 44 } 45 46 public int hasCode(){ 47 return key.hashCode(); 48 } 49 50 public String 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 64 Comparable getKey(){ 65 return this.key; 66 } 67 68 71 void setKey(Comparable key){ 72 this.key=key; 73 } 74 75 78 long getIndexOffset(){ 79 return this.indexOffset; 80 } 81 82 85 void setIndexOffset(long indexOffset){ 86 this.indexOffset=indexOffset; 87 } 88 89 void write(Marshaller keyMarshaller,DataOutput dataOut) throws IOException { 90 dataOut.writeLong(indexOffset); 91 keyMarshaller.writePayload(key,dataOut); 92 } 93 94 void read(Marshaller keyMarshaller,DataInput dataIn) throws IOException { 95 indexOffset=dataIn.readLong(); 96 key=(Comparable )keyMarshaller.readPayload(dataIn); 97 } 98 } 99 | Popular Tags |