1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.node; 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.TreeSet ; 23 24 25 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.CheckingException; 26 import SOFA.SOFAnode.Util.DFSRChecker.state.SimpleState; 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 AtomicNode extends TreeNode { 37 38 44 public AtomicNode(int eventindex, TreeSet events, ActionRepository repository) { 45 super(getProtocol(events, repository)); 46 47 this.eventIndex = eventindex; 48 this.events = events; 49 this.initState = null; 50 this.initTransitions = new TransitionPairs(new TransitionPair[1]); 51 this.initTransitions.transitions[0] = null; 52 this.secondTransitions = new TransitionPairs(new TransitionPair[0]); 53 this.nodes = new TreeNode[0]; 54 this.weight = 2; 55 this.repository = repository; 56 } 57 58 61 public long getWeight() { 62 return 2; 63 } 64 65 68 public State getInitial() { 69 if (initState == null) { 70 initState = new SimpleState(0); 71 this.initTransitions.transitions[0] = new TransitionPair(eventIndex, new SimpleState(1)); 72 } 73 74 return initState; 75 } 76 77 80 public boolean isAccepting(State state) { 81 return (((SimpleState) state).state == 1); 82 } 83 84 87 public TransitionPairs getTransitions(State state) throws InvalidParameterException, CheckingException { 88 if (((SimpleState) state).state == 0) 89 return initTransitions; 90 else if (((SimpleState) state).state == 1) 91 return secondTransitions; 92 else 93 throw new InvalidParameterException(); 94 } 95 96 99 public String [] getTypeName() { 100 String [] result = { "AtomicAction", "atomic action" }; 101 return result; 102 } 103 104 105 public TreeNode forwardCut(TreeSet livingevents) { 106 return this; 107 } 108 109 112 public AnotatedProtocol getAnotatedProtocol(State state) { 113 SimpleState sstate = (SimpleState) state; 114 String result = new String (); 115 ArrayList indicesresult = new ArrayList (); 116 117 result = protocol; 118 if (state != null) 119 if (((SimpleState)state).state == 0) 120 indicesresult.add(new Integer (0)); 121 else 122 indicesresult.add(new Integer (result.length())); 123 124 return new AnotatedProtocol(result, indicesresult); 125 } 126 127 133 private static String getProtocol(TreeSet events, ActionRepository repository) { 134 String p = new String (); 135 136 Iterator it = events.iterator(); 137 138 p = repository.getItemString(((Integer )it.next()).intValue()); 139 140 while (it.hasNext()) 141 p = p + ", " + repository.getItemString(((Integer )it.next()).intValue()); 142 143 p = "[" + p + "]"; 144 145 return p; 146 } 147 148 149 152 private int eventIndex; 153 154 157 private TreeSet events; 158 159 162 private SimpleState initState; 163 164 167 private ActionRepository repository; 168 169 172 final private TransitionPairs initTransitions; 173 174 177 final private TransitionPairs secondTransitions; 178 179 180 } 181 | Popular Tags |