package br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns;

import java.util.HashSet;
import java.util.Set;

import br.uem.din.architectureEvolution.representation.Concern;
import br.uem.din.architectureEvolution.representation.Element;
import br.uem.din.architectureEvolution.representation.Interface;
import br.uem.din.architectureEvolution.representation.Operation;

public class IIBCResult {

	private final Concern concern;
	private final Set<Concern> interlacedConcerns = new HashSet<Concern>();

	public IIBCResult(Concern concern, Element context, Interface i){
		this.concern = concern;
		addInterlacedConcerns(context, i);
	}

	public void addInterlacedConcerns(Element context, Interface i) {
		if (context.equals(i))
			addInterlacedConcerns(i);
		else if (context instanceof Operation)
			inspectOperations(i);		
		interlacedConcerns.remove(concern);
	}

	public void addInterlacedConcerns(Interface i) {
		getInterlacedConcerns().addAll(i.getConcerns());
		inspectOperations(i);		
	}

	private void inspectOperations(Interface i) {
		for (Operation operation : i.getOperations()) {
			getInterlacedConcerns().addAll(operation.getConcerns());
		}
	}

	public Concern getConcern() {
		return concern;
	}

	public Set<Concern> getInterlacedConcerns() {
		return interlacedConcerns;
	}
	
	@Override
	public String toString() {
		return concern.getName() + ": " + getInterlacedConcerns();
	}
}
