1 5 package com.jofti.btree; 6 7 import java.util.ArrayList ; 8 import java.util.Collection ; 9 import java.util.List ; 10 11 import com.jofti.exception.JoftiException; 12 import com.jofti.oswego.concurrent.ReadWriteLock; 13 14 15 16 22 public class ResultNode implements INode,IResultNode{ 23 24 private Object [] entries =null; 25 private Comparable rightValue; 26 private int entryNumber; 27 boolean isDeleted; 28 NodeLink link; 29 private INode node; 30 31 ResultNode (INode node){ 32 entries = node.getEntries(); 33 if (entries == null){ 34 throw new RuntimeException ("entries are null for "+node.getRightValue()); 35 } 36 37 entryNumber = node.getEntryNumber(); 38 rightValue = node.getRightValue(); 39 isDeleted = node.isDeleted(); 40 link = node.getLinkNode(); 41 this.node =node; 42 } 43 46 public Comparable getRightValue() 47 { 48 return rightValue; 49 } 50 51 54 public void setRightValue(Comparable value) 55 { 56 throw new UnsupportedOperationException ("Modification of node not supported"); 57 58 } 59 60 63 public boolean contains(Comparable value) 64 { 65 if (value == null) 66 { 67 return false; 68 } 69 70 return rightValue.compareTo(value) >=0; 71 } 72 73 76 public Object [] insertEntry(NodeEntry entry) throws JoftiException 77 { 78 throw new UnsupportedOperationException ("Modification of node not supported"); 79 80 } 81 82 85 public boolean deleteEntry(NodeEntry entry) 86 { 87 throw new UnsupportedOperationException ("Modification of node not supported"); 88 89 } 90 91 94 public List split() 95 { 96 throw new UnsupportedOperationException ("Modification of node not supported"); 97 98 } 99 100 103 public Node splitNode(Object [] temp) 104 { 105 106 throw new UnsupportedOperationException ("Modification of node not supported"); 107 108 } 109 110 113 public int getEntryNumber() 114 { 115 116 return entryNumber; 117 } 118 119 122 public boolean isUnderFull() 123 { 124 125 throw new UnsupportedOperationException ("Modification of node not supported"); 126 127 } 128 129 132 public boolean isEmpty() 133 { 134 135 return entryNumber == 0; 136 } 137 138 141 public boolean isDeleted() 142 { 143 144 return isDeleted; 145 } 146 147 150 public void setDeleted(boolean deleted) 151 { 152 throw new UnsupportedOperationException ("Modification of node not supported"); 153 154 155 } 156 157 160 public Object [] getEntries() 161 { 162 163 return entries; 164 165 } 166 167 170 public void setEntries(List entries) 171 { 172 throw new UnsupportedOperationException ("Modification of node not supported"); 173 174 175 } 176 177 180 public NodeLink getLinkNode() 181 { 182 183 return new ResultNodeLink(link); 184 } 185 186 public IResultNode getNextNode(){ 187 return new ResultNode(link.getNode()); 188 } 189 192 public void setLinkNode(NodeLink node) 193 { 194 throw new UnsupportedOperationException ("Modification of node not supported"); 195 196 197 } 198 201 public ReadWriteLock getNodeLock() 202 { 203 204 throw new UnsupportedOperationException ("Modification of node not supported"); 205 206 } 207 210 public LeafNodeEntry getEntry(Comparable value) 211 { 212 213 if (entries.length ==0) 214 { 215 return null; 216 } 217 219 return indexedBinaryRetrieve(entries, value); 220 221 222 } 223 224 INode getDelegate(){ 225 return node; 226 } 227 228 protected int indexedBinarySearch(Object [] arr1, Object obj) 229 { 230 int low = 0; 231 int high = entryNumber-1; 232 233 LeafNodeEntry entry =null; 234 while (low <= high) { 235 int mid = (low + high) >> 1; 236 237 entry = (LeafNodeEntry)arr1[mid]; 238 int cmp = entry.getValue().compareTo(obj); 239 240 if (cmp < 0) 241 low = mid + 1; 242 else if (cmp > 0) 243 high = mid - 1; 244 else 245 return mid; } 247 return -(low + 1); } 249 250 251 protected LeafNodeEntry indexedBinaryRetrieve(Object [] list1, Object obj) { 252 int i = 0; 253 int size = entryNumber; 254 for (int j = size- 1; i <= j;) { 255 int k = i + j >> 1; 256 LeafNodeEntry obj1 = (LeafNodeEntry)list1[k]; 257 int l = obj1.getValue().compareTo(obj); 258 if (l < 0) 259 i = k + 1; 260 else if (l > 0) 261 j = k - 1; 262 else 263 return obj1; 264 } 265 266 return null; 267 } 268 269 public int hashCode(){ 270 return node.hashCode(); 271 } 272 273 276 public Collection getEntriesBefore(Comparable value) 277 { 278 279 280 return null; 281 } 282 283 284 285 286 public boolean equals(Object obj){ 287 if (obj instanceof IResultNode){ 288 return getDelegate() == ((ResultNode)obj).getDelegate(); 289 } 290 return false; 291 } 292 public void setEntries(Object [] entries) { 293 throw new UnsupportedOperationException ("Modification of node not supported"); 294 295 } 296 297 public boolean isLeaf(){ 298 return true; 299 } 300 } 301 | Popular Tags |