package mx.udlap.settheory;

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

public class SetTheoryOperations {
	public static List<String> Union (List<List<String>> param)
	{
		//didn't use List.addall to prevent repeated values, something that doesn't happen in sets
		List<String> toReturn=new ArrayList<String>();
		for (List<String> set : param)
		{
			for(String value : set)
			{
				if(!toReturn.contains(value))
				{
					toReturn.add(value);
				}
			}
		}
		return toReturn;
	}
	
	public static List<String> Diference (List<String> minuend, List<String> subtrahend )
	{
		minuend.removeAll(subtrahend);
		return minuend;
	}
	
	public static List<String> Intersection (List<List<String>> param)
	{
		List<String> toReturn=new ArrayList<String>();
		toReturn.addAll(param.get(0)); // adds initial values to the result set
		for (List<String> set : param)
		{
			toReturn.retainAll(set);
		}
		return toReturn;
	}
	
	public static List<String> Complement (List<String> universe, List<String> a)
	{
		universe.removeAll(a);
		return universe;
	}
}

@@ -50,16 +50,42 @@
 ayList;%0A
+import java.util.HashSet;%0A
 import j
@@ -341,16 +341,63 @@
 ing%3E();%0A
+%09%09HashSet%3CString%3E hs=new HashSet%3CString%3E();%0A%09%09%0A
 %09%09for (L
@@ -428,16 +428,37 @@
 %0A%09%09%7B%0A%09%09%09
+hs.addAll(set);%0A%09%09%09/*
 for(Stri
@@ -554,21 +554,46 @@
 %09%09%7D%0A%09%09%09%7D
+*/
 %0A%09%09%7D%0A
+%09%09toReturn.addAll(hs);%0A
 %09%09return
@@ -1129,48 +1129,53 @@
 %7B%0A%09%09
-universe.removeAll(a);%0A%09%09return 
+return SetTheoryOperations.Diference(
 universe
 ;%0A%09%7D
@@ -1170,15 +1170,19 @@
 universe
+, a)
 ;%0A%09%7D%0A%7D%0A

Set theory optimization