package ch.uzh.ifi.rerg.cs.dynanalysis;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.ETypedElement;

public class RecordTable {
	
	private HashMap<EObject, Set<ETypedElement>> targets;
	private HashMap<ETypedElement, Set<EObject>> features;
	
	public RecordTable()
	{
		super();
		targets = new HashMap<EObject, Set<ETypedElement>>();
		features = new HashMap<ETypedElement, Set<EObject>>();
	}
	
	public void record(EObject target, ETypedElement feature)
	{
		Set<ETypedElement> feats = targets.get(target);
		if(feats == null)
		{
			feats = new HashSet<ETypedElement>();
			targets.put(target, feats);
		}
		feats.add(feature);
		
		Set<EObject> targs = features.get(feature);
		if(targs == null)
		{
			targs = new HashSet<EObject>();
			features.put(feature, targs);
		}
		targs.add(target);
	}
	
	public Set<EObject> getTargets(ETypedElement feature)
	{
		return features.get(feature);
	}
	
	public Set<ETypedElement> getFeatures(EObject target)
	{
		return targets.get(target);
	}
	
	public Set<EObject> getTargets()
	{
		return targets.keySet();
	}
	
	public Set<ETypedElement> getFeatures()
	{
		return features.keySet();
	}
	
	public void record(EObject target)
	{
		Set<ETypedElement> feats = targets.get(target);
		if(feats == null)
		{
			feats = new HashSet<ETypedElement>();
			targets.put(target, feats);
		}
	}
	
	public boolean exists(EObject target, ETypedElement feature)
	{
		Set<ETypedElement> features = targets.get(target);
		if(features != null)
		{
			return features.contains(feature);
		}
		else
		{
			return false;
		}
	}
}
