@@ -0,0 +1,1416 @@
+package edu.neu.ccs.pyramid.util;%0A%0Aimport java.util.Collection;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Created by chengli on 12/15/15.%0A */%0Apublic class Translator%3CT%3E %7B%0A    private Map%3CT,Integer%3E objToIndex;%0A    private Map%3CInteger,T%3E indexToObj;%0A    private int startIndex;%0A    private int currentIndex;%0A%0A    public Translator(int startIndex) %7B%0A        this.objToIndex = new HashMap%3C%3E();%0A        this.indexToObj = new HashMap%3C%3E();%0A        this.startIndex = startIndex;%0A        this.currentIndex = startIndex;%0A    %7D%0A%0A    public Translator() %7B%0A        this(0);%0A    %7D%0A%0A    public synchronized void add(T obj)%7B%0A        if (!objToIndex.containsKey(obj))%7B%0A            objToIndex.put(obj,currentIndex);%0A            indexToObj.put(currentIndex,obj);%0A            currentIndex ++;%0A        %7D%0A    %7D%0A%0A    public synchronized void addAll(Collection%3CT%3E all)%7B%0A        all.forEach(this::add);%0A    %7D%0A%0A    public int getIndex(T obj)%7B%0A        return objToIndex.get(obj);%0A    %7D%0A%0A    public T getObj(int index)%7B%0A        return indexToObj.get(index);%0A    %7D%0A%0A    public int getStartIndex() %7B%0A        return startIndex;%0A    %7D%0A%0A    public int size()%7B%0A        return this.indexToObj.size();%0A    %7D%0A%0A%0A    @Override%0A    public String toString() %7B%0A        final StringBuilder sb = new StringBuilder(%22Translator%7B%22);%0A        sb.append(%22indexToObj=%22).append(indexToObj);%0A        sb.append('%7D');%0A        return sb.toString();%0A    %7D%0A%7D%0A

add class Translator<T>