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

import java.util.Iterator;

import org.eclipse.cosmos.me.sdd.schema.DisplayTextType;
import org.eclipse.cosmos.me.sdd.schema.MaintenanceInformationType;
import org.eclipse.cosmos.me.sdd.schema.ObjectFactory;

public class MaintenanceInformationCompare
{

	protected static MaintenanceInformationType merge(MaintenanceInformationType mi1, MaintenanceInformationType mi2)
	{
		ObjectFactory objectFactory = new ObjectFactory();
		MaintenanceInformationType merged = objectFactory.createMaintenanceInformationType();
		
		merged.getSupersedes().addAll(mi1.getSupersedes());
		merged.getSupersedes().addAll(mi2.getSupersedes());
		
		merged.setSeverity(DisplayTextCompare.merge(mi1.getSeverity(), mi2.getSeverity()));
		
		Iterator <DisplayTextType> catIter = mi1.getCategory().iterator();
		
		while (catIter.hasNext())
		{
			DisplayTextType current = catIter.next();
			if (mi2.getCategory().contains(current))
				merged.getCategory().add(current);
		}
		
		merged.getFix().addAll(mi1.getFix());
		merged.getFix().addAll(mi2.getFix());
		
		
		return merged;
	}

}
