1 19 20 25 26 27 package soot.toolkits.scalar; 28 29 import soot.util.*; 30 import java.util.*; 31 32 36 class ObjectIntMapper { 37 private Vector intToObjects; 38 private int counter; 39 private Map objectToInts; 40 41 public ObjectIntMapper() { 42 intToObjects = new Vector(); 43 objectToInts = new HashMap(); 44 counter = 0; 45 } 46 47 public ObjectIntMapper(FlowUniverse flowUniverse) { 48 this(flowUniverse.iterator(), flowUniverse.size()); 49 } 50 51 public ObjectIntMapper(Collection collection) { 52 this(collection.iterator(), collection.size()); 53 } 54 55 private ObjectIntMapper(Iterator it, int initSize) { 56 intToObjects = new Vector(initSize); 57 objectToInts = new HashMap(initSize); 58 counter = 0; 59 while (it.hasNext()) 60 add(it.next()); 61 } 62 63 67 private int add(Object o) { 68 objectToInts.put(o, new Integer (counter)); 69 intToObjects.add(o); 70 return counter++; 71 } 72 73 81 public int getInt(Object o) { 82 Integer i = (Integer )objectToInts.get(o); 83 if (i != null) return i.intValue(); 84 return add(o); 85 } 86 87 93 public Object getObject(int i) { 94 return intToObjects.get(i); 95 } 96 97 103 public boolean contains(Object o) { 104 return objectToInts.containsKey(o); 105 } 106 107 110 public int size() { 111 return counter; 112 } 113 114 } 115 | Popular Tags |