package accrue.analysis.interprocanalysis;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * A utility class that is used to help record analysis results for AST nodes. An 
 * AnalysisContextMap maps analysis contexts to analysis results of type T.
 *
 * @param <T>
 */
public class AnalysisContextMap<T> {

    public AnalysisContextMap(
            Class<? extends AnalysisContext> analysisContextClass) {
        this.analysisContextClass = analysisContextClass;
    }

    public AnalysisContextMap() {
        this(AnalysisContext.class);
    }

    private final Class<? extends AnalysisContext> analysisContextClass;
    Map<AnalysisContext, T> m = new LinkedHashMap<AnalysisContext, T>();

    public void put(AnalysisContext context, T v) {
        m.put(context.convert(analysisContextClass), v);
    }

    public T remove(AnalysisContext context) {
        return m.remove(context.convert(analysisContextClass));
    }

    public T get(AnalysisContext context) {
        return m.get(context.convert(analysisContextClass));
    }

    public Set<AnalysisContext> contexts() {
        return m.keySet();
    }
}
