1 2 3 package SOFA.SOFAnode.Util; 4 5 import java.util.Hashtable ; 6 7 13 class EdgeFactory { 14 15 16 19 public static ActionToken ActionTokens[]; 20 public static int inverseActionTokens[]; 21 public static int tauActionTokens[]; 22 23 private static Hashtable idxActionTokens; 24 25 private static int nextindex; 26 27 private static int size; 28 29 public static int getActionTokensNum() { 30 return nextindex; 31 } 32 33 public static void initActionTokens() { 34 Debug.println( 2, "Initializing action tokens"); 35 ActionTokens = new ActionToken[16]; 36 inverseActionTokens = new int[16]; 37 tauActionTokens = new int[16]; 38 idxActionTokens = new Hashtable (); 39 ActionTokens[0]=new ActionToken( "NULL" ); 40 inverseActionTokens[0] = 0; tauActionTokens[0] = 0; idxActionTokens.put( new ActionToken( "NULL" ).getHashKey(), new Integer (0) ); 43 ActionTokens[1]=new ActionToken( "[UPDATE]" ); 44 inverseActionTokens[1] = 1; tauActionTokens[1] = 1; idxActionTokens.put( new ActionToken( "[UPDATE]" ).getHashKey(), new Integer (1) ); 47 nextindex = 2; 48 size = 16; 49 } 50 51 public static int getActionTokenIdx( ActionToken t ) { 52 Integer a = (Integer )idxActionTokens.get( t.getHashKey() ); 53 if( a == null ) { 54 Debug.println(3, "Not found "+t.name); 55 if( nextindex >= size-2 ) { Debug.println(3,"We need more room for action tokens"); 57 58 ActionToken newat[] = new ActionToken[ nextindex+15 ]; 60 for( int i = 0; i<nextindex; i++) newat[i] = ActionTokens[i]; 61 ActionTokens = newat; 62 63 int newint[] = new int[ nextindex+15 ]; 65 for( int i = 0; i<nextindex; i++) newint[i] = inverseActionTokens[i]; 66 inverseActionTokens = newint; 67 68 newint = new int[ nextindex+15 ]; 70 for( int i = 0; i<nextindex; i++) newint[i] = tauActionTokens[i]; 71 tauActionTokens = newint; 72 73 size = nextindex+15; 74 Debug.println(3, "Action token table resized"); 75 } 76 int ind = nextindex; 77 Debug.println(2, "Putting new action token "+t.name+" at "+ind); 78 ActionTokens[ind] = t; 79 idxActionTokens.put( t.getHashKey(), new Integer (ind) ); 80 81 int inv = findInverseActionToken( t ); 83 Debug.println(3, "Inverse is :"+inv); 84 inverseActionTokens[ind] = inv; 85 if( inverseActionTokens[ind] != -1 ) 86 inverseActionTokens[ inv ] = ind; 87 88 tauActionTokens[ind] = findTauActionToken( t ); 90 if( t.name.startsWith( "#" ) ) { 91 t = new ActionToken( "?"+t.name.substring( 1 ) ); 92 Integer k = (Integer )idxActionTokens.get( t.getHashKey() ); 93 if( k != null ) tauActionTokens[k.intValue()] = ind; 94 k = (Integer )idxActionTokens.get( t.toInverseActionToken().getHashKey() ); 95 if( k != null ) tauActionTokens[k.intValue()] = ind; 96 } 97 98 nextindex ++; 99 100 if( Debug.debug>2 ) { 101 Debug.println(3, "Actual action token table:"); 102 for( int i = 0 ; i < nextindex ; i++ ) 103 Debug.println( 3, " "+i+"\t"+ActionTokens[i].name+"\t inv:"+inverseActionTokens[i]+"\t tau:"+tauActionTokens[i]); 104 } 105 106 return nextindex-1; 107 } else return a.intValue(); 108 } 109 110 private static int findInverseActionToken( ActionToken t ) { 111 int i; 112 ActionToken inverse = t.toInverseActionToken(); 113 for( i = 0; i < nextindex ; i++ ) 114 if( ActionTokens[i].name.compareTo( inverse.name ) == 0 ) break; 115 if( i == nextindex ) return -1; 116 return i; 117 } 118 119 private static int findTauActionToken( ActionToken t ) { 120 int i; 121 for( i = 0; i < nextindex ; i++ ) 122 if( ActionTokens[i].name == t.toTauActionToken().name ) break; 123 if( i == nextindex ) return -1; 124 return i; 125 } 126 127 public static void checkTauActionToken( ActionToken t ) { 128 int i; 129 for( i = 0; i < nextindex ; i++ ) 130 if( ActionTokens[i].name == t.toTauActionToken().name ) break; 131 if( i == nextindex ) getActionTokenIdx( t.toTauActionToken() ); 132 } 133 134 } 135 | Popular Tags |