1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.node; 19 20 import java.util.TreeSet ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.TreeMap ; 24 25 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException; 26 import SOFA.SOFAnode.Util.DFSRChecker.state.CompositeState; 27 import SOFA.SOFAnode.Util.DFSRChecker.state.State; 28 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair; 29 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs; 30 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol; 31 32 33 36 public class CompositionNode extends TreeNode { 37 38 39 public CompositionNode(TreeNode node1, TreeNode node2, TreeSet events, ActionRepository repository) { 40 super("(" + node1.protocol + ")&(" + node2.protocol + ")"); 42 this.events = events; 43 this.repository = repository; 44 45 this.nodes = new TreeNode[2]; 46 this.nodes[0] = node1; 47 this.nodes[1] = node2; 48 } 49 50 54 public State getInitial() { 55 State[] states = new State[2]; 56 states[0] = nodes[0].getInitial(); 57 states[1] = nodes[1].getInitial(); 58 59 return new CompositeState(states); 60 } 61 62 66 public boolean isAccepting(State state) { 67 CompositeState cstate = (CompositeState) state; 68 69 return (nodes[0].isAccepting(cstate.states[0])) && (nodes[1].isAccepting(cstate.states[1])); 70 } 71 72 76 public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException { 77 CompositeState cstate = (CompositeState) state; 78 79 TransitionPair[] trans1 = nodes[0].getTransitions(cstate.states[0]).transitions; 80 TransitionPair[] trans2 = nodes[1].getTransitions(cstate.states[1]).transitions; 81 82 ArrayList result = new ArrayList (); 83 TreeMap sync = new TreeMap (); 84 85 for (int i = 0; i < trans1.length; ++i) { 88 Integer key = new Integer (trans1[i].eventIndex); 89 90 if (events.contains(new Integer (ActionRepository.getPure(trans1[i].eventIndex)))) 91 if (sync.containsKey(key)) 92 ((ArrayList ) sync.get(key)).add(trans1[i]); 93 else { 94 ArrayList value = new ArrayList (); 95 value.add(trans1[i]); 96 sync.put(new Integer (trans1[i].eventIndex), value); 97 } 98 else { 99 State[] states = new State[2]; 100 states[0] = trans1[i].state; 101 states[1] = cstate.states[1]; 102 103 result.add(new TransitionPair(trans1[i].eventIndex, new CompositeState(states))); 104 } 105 } 106 107 for (int i = 0; i < trans2.length; ++i) { 109 Integer key = new Integer (trans2[i].eventIndex); 110 if (events.contains(new Integer (ActionRepository.getPure(trans2[i].eventIndex)))) { 111 Integer invkey = new Integer (repository.getInverseAction(trans2[i].eventIndex)); 112 if (sync.containsKey(invkey)) { 113 Iterator it = ((ArrayList ) sync.get(invkey)).iterator(); 114 115 while (it.hasNext()) { 116 State[] states = new State[2]; 117 states[0] = (State) it.next(); 118 states[1] = trans2[i].state; 119 120 result.add(new TransitionPair(repository.getTauAction(trans2[i].eventIndex), new CompositeState(states))); 121 } 122 } 123 } else { 124 State[] states = new State[2]; 125 states[0] = cstate.states[0]; 126 states[1] = trans2[i].state; 127 128 result.add(new TransitionPair(trans2[i].eventIndex, new CompositeState(states))); 129 } 130 131 } 132 133 TransitionPair[] result1 = new TransitionPair[result.size()]; 134 Iterator it = result.iterator(); 135 int i = 0; 136 137 while (it.hasNext()) 138 result1[i++] = (TransitionPair) it.next(); 139 140 return new TransitionPairs(result1); 141 142 } 143 144 148 public long getWeight() { 149 if (weight != -1) 150 return weight; 151 else { 152 return weight = nodes[0].getWeight() * nodes[1].getWeight(); 153 } 154 } 155 156 160 public TreeNode forwardCut(TreeSet livingevents) { 161 TreeSet exlivev = new TreeSet (livingevents); 162 163 exlivev.addAll(events); 164 TreeSet exlivev2 = new TreeSet (exlivev); 165 166 nodes[0] = nodes[0].forwardCut(exlivev); 167 nodes[1] = nodes[1].forwardCut(exlivev2); 168 169 if ((nodes[0] == null) || (nodes[1] == null)) 170 return null; 171 172 else 173 return this; 174 } 175 176 179 public String [] getTypeName() { 180 String [] result = { "Composition", "&" }; 181 return result; 182 } 183 184 185 188 public AnotatedProtocol getAnotatedProtocol(State state) { 189 throw new RuntimeException (this.getClass().getName() + ".getAnotatedProtocol is not implemented"); 190 } 191 192 193 194 196 199 final private TreeSet events; 200 201 204 private ActionRepository repository; 205 206 } | Popular Tags |