1 2 3 package SOFA.SOFAnode.Util; 4 5 import java.util.Iterator ; 6 7 class ProtocolAlternative extends ProtocolBinaryOperator { 8 9 public ProtocolAlternative( Protocol l, Protocol r ) { 10 super( "+",l,r ); 11 } 12 13 public Protocol Copy() { 14 return new ProtocolAlternative( left.Copy(), right.Copy() ); 15 } 16 17 public Machine createMachine() { 18 Debug.println(3, "Alternative create machine start:"); 19 20 machineImpl m1 = (machineImpl)left.createMachine(); 21 machineImpl m2 = (machineImpl)right.createMachine(); 22 23 if( m1 == null ) return m2; if( m2 == null ) return m1; 26 Debug.println(3, "Alternative first machine:" ); 27 ((Printer)m1).Print(3); 28 Debug.println(3, "Alternative second machine:" ); 29 ((Printer)m2).Print(3); 30 31 boolean start_is_stop = m2.Stop().containsKey( new Integer (m2.Start())); 32 int map[] = m1.AddStates( m2.states, m2.nextID ); m1.Merge(m1.Start(), map[m2.Start()] ); for( Iterator i = m2.Stop().values().iterator(); i.hasNext(); ) 35 m1.AddStop( map[ ((Integer )i.next()).intValue()] ); 37 for( Iterator i = m2.Update().values().iterator(); i.hasNext(); ) 38 m1.addUpdateEdge( map[ ((Integer )i.next()).intValue()] ); 40 42 if( start_is_stop ) m1.AddStop( m1.Start() ); 43 44 m1.Minimize(); 45 46 Debug.println(3, "Alternative create machine finished:"); 47 ((Printer)m1).Print(3); 48 49 return m1; 50 } 51 52 public Protocol getSameType( Object p1, Object p2 ) { 53 return new ProtocolAlternative( (Protocol)p1, (Protocol)p2 ); 54 } 55 } 56 57 | Popular Tags |