KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Util > ProtocolRestriction


1 /* $Id: ProtocolRestriction.java,v 1.2 2004/05/20 14:23:53 bures Exp $ */
2
3 package SOFA.SOFAnode.Util;
4
5
6 class ProtocolRestriction extends ProtocolOperator {
7
8     protected ActionTokenArray restrict;
9     protected Protocol nested;
10
11     public ProtocolRestriction( Protocol l, ActionTokenArray r ) {
12     super( "\\" );
13     restrict = r;
14     nested = l;
15     }
16     
17     public Protocol Copy() {
18     return new ProtocolRestriction( nested.Copy(), new ActionTokenArray( restrict ));
19     }
20     
21     public Machine createMachine() {
22         
23     Machine m1 = nested.createMachine();
24         
25     m1.Restrict( restrict );
26
27     m1.Minimize();
28
29     return m1;
30     }
31     
32     public boolean Restrict( ActionTokenArray a ) {
33     ActionTokenArray h = new ActionTokenArray( a );
34     for( int i = 0 ; i < a.size; i++ )
35         h.tokens[i] = h.tokens[i] || restrict.tokens[i];
36     return nested.Restrict( h );
37     }
38
39     public void Print( int level ) {
40     super.Print( level );
41     Debug.println( level, "Restrict set: "+restrict.toList() );
42     nested.Print( level );
43     }
44
45     public Protocol Left() {
46     return nested;
47     }
48
49     public Protocol getSameType( Object JavaDoc p1, Object JavaDoc p2 ) {
50     return new ProtocolRestriction( (Protocol)p1, new ActionTokenArray( restrict ) );
51     }
52 }
53
Popular Tags