1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.node; 19 20 import java.util.ArrayList ; 21 import java.util.TreeSet ; 22 23 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException; 24 import SOFA.SOFAnode.Util.DFSRChecker.state.State; 25 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair; 26 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs; 27 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol; 28 29 30 33 public class RepetitionNode extends TreeNode { 34 35 36 public RepetitionNode(TreeNode node) { 37 super("(" + node.protocol + ")*"); 39 this.nodes = new TreeNode[1]; 40 this.nodes[0] = node; 41 42 this.initial = null; 45 47 } 48 49 52 public State getInitial() { 53 if (initial == null) 54 initial = nodes[0].getInitial(); 55 56 return initial; 57 } 58 59 62 public boolean isAccepting(State state) { 63 return this.initial.equals(state) || nodes[0].isAccepting(state); 64 } 65 66 70 93 94 97 public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException { 98 State initial = nodes[0].getInitial(); 99 100 TransitionPair[] origtrans = nodes[0].getTransitions(state).transitions; 101 int transcnt = origtrans.length; 102 103 if (nodes[0].isAccepting(state)) { 104 initial = nodes[0].getInitial(); 105 TransitionPair[] trans = nodes[0].getTransitions(initial).transitions; 106 107 TransitionPair[] result = new TransitionPair[trans.length + transcnt]; 108 109 for (int i = 0; i < transcnt; ++i) 110 result[i] = origtrans[i]; 111 112 for (int i = 0; i < trans.length; ++i) 113 result[i + transcnt] = trans[i]; 114 115 return new TransitionPairs(result); 116 } 117 118 else { 119 return new TransitionPairs(origtrans); 120 } 121 } 122 123 124 127 public long getWeight() { 128 if (weight != -1) 129 return weight; 130 else { 131 return weight = nodes[0].getWeight(); 132 } 133 } 134 135 138 public String [] getTypeName() { 139 String [] result = { "Repetition", "*" }; 140 return result; 141 } 142 143 146 public TreeNode forwardCut(TreeSet livingevents) { 147 TreeNode active = null; 148 int cnt = 0; 149 150 nodes[0] = nodes[0].forwardCut(livingevents); 151 if (nodes[0] != null) { 152 if (nodes[0] instanceof RepetitionNode) 153 return nodes[0]; 154 else 155 return this; 156 } else 157 return null; 158 159 } 160 161 166 public int getLeafCount() { 167 return (nodes[0].getLeafCount()) * 2; 168 } 169 170 173 public AnotatedProtocol getAnotatedProtocol(State state) { 174 String result = new String ();; 175 ArrayList indices = new ArrayList (); 176 177 result = "("; 178 179 AnotatedProtocol subresult = nodes[0].getAnotatedProtocol(state); 180 181 for (int i = 0 ; i < subresult.indices.size(); ++i) 182 indices.add(new Integer (((Integer )subresult.indices.get(i)).intValue() + result.length())); 183 184 result += subresult.protocol + ")*"; 185 186 return new AnotatedProtocol(result, indices); 187 } 188 189 194 private State initial; 195 196 } | Popular Tags |