1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.node; 19 20 import java.util.TreeSet ; 21 import java.util.ArrayList ; 22 import java.util.TreeMap ; 23 import java.util.Iterator ; 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 AdjustmentNode extends TreeNode { 37 38 39 public AdjustmentNode(TreeNode node1, TreeNode node2, TreeSet events) { 40 super("(" + node1.protocol + ") " + "|S|" + " (" + node2.protocol + ")"); 42 this.events = events; 43 this.nodes = new TreeNode[2]; 44 this.nodes[0] = node1; 45 this.nodes[1] = node2; 46 } 47 48 52 public State getInitial() { 53 State[] states = new State[2]; 54 states[0] = nodes[0].getInitial(); 55 states[1] = nodes[1].getInitial(); 56 57 return new CompositeState(states); 58 } 59 60 64 public boolean isAccepting(State state) { 65 CompositeState cstate = (CompositeState) state; 66 67 return (nodes[0].isAccepting(cstate.states[0])) && (nodes[1].isAccepting(cstate.states[1])); 68 } 69 70 74 public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException { 75 CompositeState cstate = (CompositeState) state; 76 77 TransitionPair[] trans1 = nodes[0].getTransitions(cstate.states[0]).transitions; 78 TransitionPair[] trans2 = nodes[1].getTransitions(cstate.states[1]).transitions; 79 80 ArrayList result = new ArrayList (); 81 TreeMap sync = new TreeMap (); 82 83 for (int i = 0; i < trans1.length; ++i) { 86 Integer key = new Integer (trans1[i].eventIndex); 87 Integer basekey = new Integer (ActionRepository.getPure(key.intValue())); 88 89 if (events.contains(basekey)) 90 if (sync.containsKey(key)) 91 ((ArrayList ) sync.get(key)).add(trans1[i]); 92 else { 93 ArrayList value = new ArrayList (); 94 value.add(trans1[i]); 95 sync.put(new Integer (trans1[i].eventIndex), value); 96 } 97 else { 98 State[] states = new State[2]; 99 states[0] = trans1[i].state; 100 states[1] = cstate.states[1]; 101 102 result.add(new TransitionPair(trans1[i].eventIndex, new CompositeState(states))); 103 } 104 } 105 106 for (int i = 0; i < trans2.length; ++i) { 108 Integer key = new Integer (trans2[i].eventIndex); 109 Integer basekey = new Integer (ActionRepository.getPure(key.intValue())); 110 111 if (events.contains(basekey)) { 112 if (sync.containsKey(key)) { 113 Iterator it = ((ArrayList ) sync.get(key)).iterator(); 114 115 while (it.hasNext()) { 116 State[] states = new State[2]; 117 states[0] = ((TransitionPair) it.next()).state; 118 states[1] = trans2[i].state; 119 120 result.add(new TransitionPair(trans2[i].eventIndex, new CompositeState(states))); 121 } 122 } 123 } 124 125 else { 126 State[] states = new State[2]; 127 states[0] = cstate.states[0]; 128 states[1] = trans2[i].state; 129 130 result.add(new TransitionPair(trans2[i].eventIndex, new CompositeState(states))); 131 } 132 } 133 134 TransitionPair[] result1 = new TransitionPair[result.size()]; 135 Iterator it = result.iterator(); 136 int i = 0; 137 138 while (it.hasNext()) 139 result1[i++] = (TransitionPair) it.next(); 140 141 return new TransitionPairs(result1); 142 } 143 144 147 public long getWeight() { 148 if (weight != -1) 149 return weight; 150 else { 151 return weight = nodes[0].getWeight() * nodes[1].getWeight(); 152 } 153 } 154 155 158 public TreeNode forwardCut(TreeSet livingevents) { 159 TreeSet exlivev = new TreeSet (livingevents); 160 161 exlivev.addAll(events); 162 TreeSet exlivev2 = new TreeSet (exlivev); 163 164 nodes[0] = nodes[0].forwardCut(exlivev); 165 nodes[1] = nodes[1].forwardCut(exlivev2); 166 167 if ((nodes[0] == null) || (nodes[1] == null)) 168 return null; 169 170 else 171 return this; 172 } 173 174 177 public String [] getTypeName() { 178 String [] result = { "Adjustment", "/" }; 179 return result; 180 } 181 182 185 public AnotatedProtocol getAnotatedProtocol(State state) { 186 throw new RuntimeException (this.getClass().getName() + ".getAnotatedProtocol is not implemented"); 187 } 188 189 191 194 final private TreeSet events; 195 196 197 } | Popular Tags |