1 17 18 package SOFA.SOFAnode.Util.DFSRChecker.node; 19 20 import java.util.ArrayList ; 21 import java.util.TreeSet ; 22 23 24 import SOFA.SOFAnode.Util.DFSRChecker.state.SimpleState; 25 import SOFA.SOFAnode.Util.DFSRChecker.state.State; 26 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPair; 27 import SOFA.SOFAnode.Util.DFSRChecker.state.TransitionPairs; 28 import SOFA.SOFAnode.Util.DFSRChecker.utils.AnotatedProtocol; 29 30 31 35 public class EventNode extends TreeNode { 36 37 38 public EventNode(int eventindex, ActionRepository repository) { 39 super(repository.getItemString(eventindex)); 40 this.eventIndex = eventindex; 41 42 this.initState = new SimpleState(0); 43 44 this.initTransitions = new TransitionPairs(new TransitionPair[1]); 45 this.initTransitions.transitions[0] = new TransitionPair(eventindex, new SimpleState(1)); 46 47 this.secondTransitions = new TransitionPairs(new TransitionPair[0]); 48 49 this.nodes = new TreeNode[0]; 50 51 this.weight = 2; 52 53 } 54 55 59 public State getInitial() { 60 return initState; 61 } 62 63 67 public boolean isAccepting(State state) { 68 return (((SimpleState) state).state == 1); 69 } 70 71 75 public TransitionPairs getTransitions(State state) throws InvalidParameterException { 76 if (((SimpleState) state).state == 0) 77 return initTransitions; 78 else if (((SimpleState) state).state == 1) 79 return secondTransitions; 80 else 81 throw new InvalidParameterException(); 82 } 83 84 88 public long getWeight() { 89 return 2; 90 } 91 92 96 public TreeNode forwardCut(TreeSet livingevents) { 97 if (livingevents.contains(new Integer (eventIndex))) 98 return this; 99 else 100 return null; 101 } 102 103 106 public String [] getTypeName() { 107 String [] result = { "Event", "" }; 108 return result; 109 } 110 111 114 public int getEventIndex() { 115 return eventIndex; 116 } 117 118 public int getLeafCount() { 119 return 1; 120 } 121 122 125 public AnotatedProtocol getAnotatedProtocol(State state) { 126 SimpleState sstate = (SimpleState) state; 127 String result = new String (); 128 ArrayList indicesresult = new ArrayList (); 129 130 result = protocol; 131 if (state != null) 132 if (((SimpleState)state).state == 0) 133 indicesresult.add(new Integer (0)); 134 else 135 indicesresult.add(new Integer (result.length())); 136 137 return new AnotatedProtocol(result, indicesresult); 138 } 139 140 141 145 final private int eventIndex; 146 147 150 private SimpleState initState; 151 152 155 final private TransitionPairs initTransitions; 156 157 160 final private TransitionPairs secondTransitions; 161 162 } | Popular Tags |