1 2 3 package SOFA.SOFAnode.Util; 4 5 import java.util.Iterator ; 6 7 class ProtocolSequence extends ProtocolBinaryOperator { 8 9 public ProtocolSequence( Protocol l, Protocol r ) { 10 super( ";",l,r ); 11 } 12 13 public Protocol Copy() { 14 return new ProtocolSequence( left.Copy(), right.Copy() ); 15 } 16 17 public Machine createMachine() { 18 machineImpl result = (machineImpl)left.createMachine(); 19 machineImpl m = (machineImpl)right.createMachine(); 20 21 if( m.Stop().containsKey( new Integer (m.Start()) ) ) { Debug.println(3, "Sequence build start is stop " ); 23 24 Debug.println(3, "Sequence first machine:"); 25 ((Printer)result).Print(3); 26 Debug.println(3, "Sequence second machine:"); 27 ((Printer)m).Print(3); 28 29 Debug.println(3, "Sequence result after new copy for start state" ); 30 ((Printer)result).Print(3); 31 32 int map[] = result.AddStates( m.states, m.nextID ); 33 34 Iterator i = result.Stop().values().iterator(); 35 while( i.hasNext() ) 36 result.Merge( ((Integer )i.next()).intValue(), map[m.Start()] ); 37 38 for( i = m.Stop().values().iterator(); i.hasNext() ; ) 39 result.AddStop( map[ ((Integer )i.next()).intValue()] ); 40 for( i = m.Update().values().iterator(); i.hasNext() ; ) 41 result.addUpdateEdge( map[ ((Integer )i.next()).intValue()] ); 42 43 } else { Debug.println(3, "Sequence build start is not stop " ); 45 int map[] = result.AddStates( m.states, m.nextID ); 46 47 Iterator i = result.Stop().values().iterator(); 48 while( i.hasNext() ) 49 result.Merge( ((Integer )i.next()).intValue(), map[m.Start()] ); 50 51 result.ClearStops(); 52 53 for( i = m.Stop().values().iterator(); i.hasNext() ; ) 54 result.AddStop( map[ ((Integer )i.next()).intValue()] ); 55 for( i = m.Update().values().iterator(); i.hasNext() ; ) 56 result.addUpdateEdge( map[ ((Integer )i.next()).intValue()] ); 57 58 ((Printer)result).Print(3); 59 } 60 61 result.Minimize(); 62 63 Debug.println(2,"Sequence result:"); 64 ((Printer)result).Print(2); 65 66 return result; 67 } 68 69 public Protocol getSameType( Object p1, Object p2 ) { 70 return new ProtocolSequence( (Protocol)p1, (Protocol)p2 ); 71 } 72 } 73 74 | Popular Tags |