1 package hudson.remoting; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 11 final class ExportTable<T> { 12 private final Map <Integer ,T> table = new HashMap <Integer ,T>(); 13 private final Map <T,Integer > reverse = new HashMap <T,Integer >(); 14 15 18 private int iota = 1; 19 20 31 public synchronized int export(T t) { 33 if(t==null) return 0; 35 Integer id = reverse.get(t); 36 if(id==null) { 37 id = iota++; 38 table.put(id,t); 39 reverse.put(t,id); 40 } 41 42 return id; 43 } 44 45 public synchronized T get(int id) { 46 return table.get(id); 47 } 48 49 52 public synchronized void unexport(T t) { 53 if(t==null) return; 54 Integer id = reverse.remove(t); 55 if(id==null) return; table.remove(id); 57 } 58 } 59 | Popular Tags |