1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.node; 19 20 import java.util.TreeSet ; 21 22 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException; 23 import SOFA.SOFAnode.Util.DFSRChecker.state.State; 24 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs; 25 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol; 26 27 28 32 abstract public class TreeNode implements Cloneable { 33 34 35 public TreeNode(String protocol) { 36 this.protocol = protocol; 37 weight = -1; 38 } 39 40 44 abstract public long getWeight(); 45 46 49 public TreeNode[] getChildren() { 50 return nodes; 51 } 52 53 56 public void changeChild(int index, TreeNode newChild) throws ArrayIndexOutOfBoundsException { 57 nodes[index] = newChild; 58 } 59 60 68 public TreeNode forwardCut(TreeSet livingevents) { 69 TreeNode active = null; 70 int cnt = 0; 71 72 for (int i = 0; i < nodes.length; ++i) { 73 nodes[i] = nodes[i].forwardCut(livingevents); 74 if (nodes[i] != null) { 75 ++cnt; 76 active = nodes[i]; 77 } 78 } 79 80 if (cnt == 0) 82 return null; 83 84 else if ((cnt == 1) && (nodes.length > 1)) 87 return active; 88 89 else if (nodes.length != cnt) { 91 TreeNode[] newchildren = new TreeNode[cnt]; 92 93 for (int i = 0, j = 0; i < cnt; ++i) { 94 while (nodes[j] == null) 95 ++j; 96 97 newchildren[i] = nodes[j++]; 98 } 99 100 nodes = newchildren; 101 102 } 103 104 return this; 105 } 106 107 113 public TreeNode copy() { 114 TreeNode newnode = null; 115 try { 116 newnode = (TreeNode) this.clone(); 117 } catch (CloneNotSupportedException e) { 118 return null; 119 } 120 121 newnode.nodes = new TreeNode[this.nodes.length]; 122 123 for (int i = 0; i < this.nodes.length; ++i) { 124 newnode.nodes[i] = this.nodes[i].copy(); 125 } 126 127 return newnode; 128 } 129 130 134 public int getLeafCount() { 135 int cnt = 0; 136 for (int i = 0; i < nodes.length; ++i) 137 cnt += nodes[i].getLeafCount(); 138 139 return cnt; 140 } 141 142 145 abstract public AnotatedProtocol getAnotatedProtocol(State state); 146 147 151 abstract public State getInitial(); 152 153 156 abstract public boolean isAccepting(State state); 157 158 166 abstract public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException; 167 168 171 abstract public String [] getTypeName(); 172 173 175 176 179 protected TreeNode[] nodes; 180 181 184 protected long weight; 185 186 189 public String protocol; 190 191 } 192 193 | Popular Tags |