package org.eclipse.cosmos.me.sdd.tooling.btg.aggregator.comparisons;

import org.eclipse.cosmos.me.sdd.schema.ConditionType;
import org.eclipse.cosmos.me.sdd.schema.ObjectFactory;

public class ConditionCompare
{

	protected static ConditionType merge(ConditionType condition, ConditionType condition2)
	{
		if (equals(condition,condition2))
		{
			ObjectFactory objectFactory = new ObjectFactory();
			ConditionType merged = objectFactory.createConditionType();
			
			merged.getOperation().addAll(condition.getOperation());
			
			merged.getAlternative().addAll(AlternativeConditionalCompare.merge(condition.getAlternative(),condition2.getAlternative()));
			merged.setDescription(DisplayTextCompare.merge(condition.getDescription(), condition2.getDescription()));
			merged.setDisplayName(DisplayTextCompare.merge(condition.getDisplayName(), condition2.getDisplayName()));
			merged.getResourceConstraint().addAll(ConditionalResourceConstraintCompare.merge(condition.getResourceConstraint(),condition2.getResourceConstraint()));
			merged.setShortDescription(DisplayTextCompare.merge(condition.getShortDescription(), condition2.getShortDescription()));
			
			return merged;
			
		}
		else return null;
	}

	protected static boolean equals(ConditionType condition, ConditionType condition2)
	{		
		return OperationCompare.equals(condition.getOperation(), condition.getOperation());
	}

}
