1 19 20 package soot.util; 21 import java.util.*; 22 23 public class MapNumberer implements Numberer { 24 Map map = new HashMap(); 25 ArrayList al = new ArrayList(); 26 int nextIndex = 1; 27 public void add( Object o ) { 28 if( !map.containsKey(o) ) { 29 map.put( o, new Integer (nextIndex) ); 30 al.add(o); 31 nextIndex++; 32 } 33 } 34 public Object get( long number ) { 35 return al.get((int) number); 36 } 37 public long get( Object o ) { 38 if( o == null ) return 0; 39 Integer i = (Integer ) map.get(o); 40 if( i == null ) throw new RuntimeException ( "couldn't find "+o ); 41 return i.intValue(); 42 } 43 public int size() { return nextIndex; } 44 public MapNumberer() { al.add(null); } 45 public boolean contains(Object o) { return map.containsKey(o); } 46 } 47 | Popular Tags |