package br.uem.din.architectureEvolution.helpers;

import static br.uem.din.architectureEvolution.helpers.ElementTypeNames.CLASS;
import static br.uem.din.architectureEvolution.helpers.ElementTypeNames.COMPONENT;
import static br.uem.din.architectureEvolution.helpers.ElementTypeNames.INTERFACE;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.sdmetrics.model.ModelElement;

public class ModelElementHelper {
	
	public static List<ModelElement> getOwnedElementsOfType(ModelElement element, String type) {
		List<ModelElement> elements = new ArrayList<ModelElement>();
		Collection<ModelElement> ownedElements = element.getOwnedElements();

		if (ownedElements == null)
			return elements;

		for (ModelElement subElement : ownedElements) {
			if (subElement.getType().getName().equalsIgnoreCase(type)) {
				elements.add(subElement);
			}
		}
		return elements;
	}

	@SuppressWarnings("unchecked")
	public static Collection<ModelElement> getStereotypes(ModelElement element) {
		Collection<ModelElement> stereotypes = (Collection<ModelElement>) element.getSetAttribute("stereotypes");
		return stereotypes;
	}
	
	public static boolean isInterface(ModelElement modelElement) {
		return modelElement.getType().getName().equals(INTERFACE);
	}

	public static boolean isClass(ModelElement modelElement) {
		return modelElement.getType().getName().equals(CLASS);
	}

	public static boolean isComponent(ModelElement modelElement) {
		return modelElement.getType().getName().equals(COMPONENT);
	}
}
