/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.logic;

import java.util.Set;
import java.util.HashSet;

public class SetUtil {

    private SetUtil() {
	// not instantiable
    }

    public static <T> Set<T> union(Set<T> set1, Set<T> set2) {
	Set<T> result = new HashSet<T>(set1);
	result.addAll(set2);
	return result;
    }

    public static <T> Set<T> intersection(Set<T> set1, Set<T> set2) {
	Set<T> result = new HashSet<T>();
	for (T e : set1)
	    if (set2.contains(e))
		result.add(e);
	return result;
    }

    public static <T> Set<T> difference(Set<T> set1, Set<T> set2) {
	Set<T> result = new HashSet<T>(set1);
	result.removeAll(set2);
	return result;
    }

    public static <T> boolean isSubset(Set<T> set1, Set<T> set2) {
	return set2.containsAll(set1);
    }

    public static <T> boolean isSuperset(Set<T> set1, Set<T> set2) {
	return set1.containsAll(set2);
    }

}

@@ -410,19 +410,26 @@
 va.util.
-Set
+Comparator
 ;%0Aimport
@@ -447,16 +447,38 @@
 HashSet;
+%0Aimport java.util.Set;
 %0A%0Apublic
@@ -539,32 +539,245 @@
 antiable%0A    %7D%0A%0A
+    public static Comparator%3CSet%3C?%3E%3E TOPOLOGICAL_SET_COMPARATOR = new TopologicalSetComparator();%0A    public static Comparator%3CSet%3C?%3E%3E REVERSE_TOPOLOGICAL_SET_COMPARATOR = new ReversesTopologicalSetComparator();%0A%0A
     public stati
@@ -1419,32 +1419,32 @@
  Set%3CT%3E set2) %7B%0A
-
 %09return set1.con
@@ -1466,10 +1466,380 @@
 %0A    %7D%0A%0A
+    static class TopologicalSetComparator implements Comparator%3CSet%3C?%3E%3E%7B%0A%09@Override%0A%09public int compare(Set%3C?%3E set1, Set%3C?%3E set2) %7B%0A%09    return set2.size() - set1.size();%0A%09%7D%0A    %7D%0A%0A    static class ReversesTopologicalSetComparator implements Comparator%3CSet%3C?%3E%3E%7B%0A%09@Override%0A%09public int compare(Set%3C?%3E set1, Set%3C?%3E set2) %7B%0A%09    return set1.size() - set2.size();%0A%09%7D%0A    %7D%0A%0A
 %7D%0A

Add topological set comparators