1 6 7 package com.jofti.btree; 8 9 10 import com.jofti.core.IStoreKey; 11 import com.jofti.core.IStoreManager; 12 13 14 20 class NodeFactory { 21 22 private static NodeFactory factory = null; 23 IStoreManager manager =null; 24 25 26 private NodeFactory() { 27 } 28 29 private NodeFactory(IStoreManager manager){ 30 this.manager = manager; 31 } 32 33 37 static synchronized NodeFactory getInstance() { 38 if (factory == null){ 39 factory = new NodeFactory(); 40 41 } 42 return factory; 43 } 44 45 52 static synchronized NodeFactory getInstance(IStoreManager manager) { 53 if (factory == null){ 54 factory = new NodeFactory(manager); 55 56 } 57 return factory; 58 } 59 60 IndexNode createIndexNode() { 61 return new IndexNode(); 62 } 63 64 Node createLeafNode() { 65 Node temp =null; 66 if (manager != null){ 67 try { 68 IStoreKey storeKey = manager.getNextKey(); 69 temp = new PagedLeafNode(manager,storeKey); 70 } catch (Exception e){ 71 throw new RuntimeException ("unable to get node ",e); 72 } 73 74 75 }else{ 76 temp = new LeafNode(); 77 } 78 79 return temp; 80 } 81 82 83 IndexNodeEntry createIndexNodeEntry() { 84 return new IndexNodeEntry(); 85 } 86 87 LeafNodeEntry createLeafNodeEntry() { 88 return new LeafNodeEntry(); 89 } 90 91 LeafNodeEntry createMaxLeafNodeEntry() { 92 93 return new MaxLeafNodeEntry(); 94 95 } 96 97 LeafNodeEntry createLeafNodeEntry(Object uniqueId, Comparable value) { 98 return new LeafNodeEntry(uniqueId,value); 99 } 100 101 } 102 | Popular Tags |