1 8 9 package net.sourceforge.chaperon.process.extended; 10 11 public class StackNodeSet 12 { 13 private StackNode[] nodes = new StackNode[10]; 14 private int position = 0; 15 private int count = 0; 16 public int watchdog = 0; 17 18 public void push(StackNode stackNode) 19 { 20 watchdog++; 21 23 for (int i = 0; i<count; i++) 24 { 25 if (nodes[i].pattern==stackNode.pattern) 26 { 27 for (StackNode node = nodes[i]; node!=null; node = node.sibling) 29 { 30 if (node.ancestor==stackNode.ancestor) 32 { 33 return; 35 } 36 37 if (node.sibling==null) 38 { 39 node.sibling = stackNode; 40 break; 41 } 42 } 43 44 if (i<position) { 46 54 position=0; 55 } 56 57 return; 58 } 59 } 60 61 if (nodes.length==(count+1)) 62 { 63 StackNode[] newNodes = new StackNode[nodes.length+10]; 64 System.arraycopy(nodes, 0, newNodes, 0, nodes.length); 65 nodes = newNodes; 66 } 67 68 nodes[count++] = stackNode; 69 } 70 71 public StackNode pop() 72 { 73 if (position>=count) 74 throw new java.util.EmptyStackException (); 75 76 return nodes[position++]; 77 } 78 79 public void clear() 80 { 81 position = 0; 82 count = 0; 83 watchdog = 0; 84 } 85 86 public boolean isEmpty() 87 { 88 return position>=count; 89 } 90 91 public int size() 92 { 93 return count-position; 94 } 95 96 public String toString() 97 { 98 StringBuffer buffer = new StringBuffer (); 99 buffer.append("{"); 100 101 for (int i = 0; i<count; i++) 102 { 103 if (i==position) 104 buffer.append("|"); 105 106 buffer.append(nodes[i].toString()); 107 108 if (((i+1)!=position) && (i<(count-1))) 109 buffer.append(","); 110 } 111 112 if (count==position) 113 buffer.append("|"); 114 115 buffer.append("}\n"); 116 117 return buffer.toString(); 118 } 119 120 public String dump() 121 { 122 StringBuffer buffer = new StringBuffer (); 123 124 for (int i = 0; i<count; i++) 125 buffer.append(nodes[i].dump()); 126 127 return buffer.toString(); 128 } 129 } 130 | Popular Tags |