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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

public class StringCompare {
	
	protected static boolean equals(String s1, String s2)
	{
		if(s1 != null) {
			return s1.equals(s2);
		}
		else {
			return s2 == null;
		}
	}
	protected static String merge(String s1, String s2)
	{
		if ((s1==null)&&(s2!=null))
			return s2;
		if ((s1!=null)&&(s2==null))
			return s1;
		if ((s1==null)&&(s2==null))
			return null;
		
		return s1.concat(s2);
	}
	public static boolean equals(QName type, QName type2) {
		// TODO Auto-generated method stub
		return false;
	}
	public static String mergeVersion(String s1, String s2)
	{
		if ((s1==null)&&(s2!=null))
			return s2;
		if ((s1!=null)&&(s2==null))
			return s1;
		if ((s1==null)&&(s2==null))
			return null;
		
		return s1.concat(s2);
	}
	
	protected static boolean equals(List<String> s,	List<String> s2)
	{
		if (s.size()!=s2.size())
			return false;
		
		Iterator <String> iter = s.iterator();
		
		while (iter.hasNext())
		{
			String o = iter.next();
			if (s2.contains(o)==false)
				return false;
			else
				s2.remove(o);
		}
		
		return true;
	}
	protected static boolean equalsJAXBList(List<JAXBElement<String>> value,
			List<JAXBElement<String>> value2)
	{
		ArrayList <String> s1 = new ArrayList <String> ();
		ArrayList <String> s2 = new ArrayList <String> ();
		
		Iterator <JAXBElement<String>> iter1 = value.iterator();
		Iterator <JAXBElement<String>> iter2 = value2.iterator();
		
		while (iter1.hasNext())
		{
			s1.add(iter1.next().getValue());
		}
		
		while (iter2.hasNext())
		{
			s2.add(iter2.next().getValue());
		}
		
		return equals(s1,s2);
	}
}
