1 14 15 package org.apache.activemq.kaha.impl.index.tree; 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 TreeEntry implements Comparable { 28 29 static final int NOT_SET=-1; 30 private Comparable key; 31 private long indexOffset; 32 private long prevPageId=NOT_SET; 33 private long nextPageId=NOT_SET; 34 35 public int compareTo(Object 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 o){ 45 return compareTo(o)==0; 46 } 47 48 public int hasCode(){ 49 return key.hashCode(); 50 } 51 52 public String 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 72 Comparable getKey(){ 73 return this.key; 74 } 75 76 79 void setKey(Comparable key){ 80 this.key=key; 81 } 82 83 86 long getNextPageId(){ 87 return this.nextPageId; 88 } 89 90 93 void setNextPageId(long nextPageId){ 94 this.nextPageId=nextPageId; 95 } 96 97 100 long getPrevPageId(){ 101 return this.prevPageId; 102 } 103 104 107 void setPrevPageId(long prevPageId){ 108 this.prevPageId=prevPageId; 109 } 110 111 114 long getIndexOffset(){ 115 return this.indexOffset; 116 } 117 118 119 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 dataOut) throws IOException { 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 dataIn) throws IOException { 138 key=(Comparable )keyMarshaller.readPayload(dataIn); 139 indexOffset=dataIn.readLong(); 140 nextPageId=dataIn.readLong(); 141 prevPageId=dataIn.readLong(); 142 } 143 144 145 146 } 147 | Popular Tags |