1 package gov.nasa.jpf.jvm; 20 21 import java.util.Hashtable ; 22 23 24 28 public class StaticMap { 29 static Hashtable mapping = new Hashtable (); 30 static int counter = 0; 31 32 public static int getEntry (String cname) { 33 return ((Integer ) mapping.get(cname)).intValue(); 34 } 35 36 public static int addEntry (String cname) { 37 Integer index = (Integer ) mapping.get(cname); 38 39 if (index != null) { 40 return index.intValue(); 41 } 42 synchronized (StaticMap.class) { 43 index = (Integer ) mapping.get(cname); 44 45 if (index != null) { 46 return index.intValue(); 47 } 48 49 mapping.put(cname, new Integer (counter)); 50 51 return counter++; 52 } 53 } 54 55 public static boolean hasEntry (String cname) { 56 return mapping.containsKey(cname); 57 } 58 59 public static synchronized void init () { 60 mapping = new Hashtable (); 61 counter = 0; 62 } 63 } | Popular Tags |