package org.workcraft.utils;

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

public class SetUtils {

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

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

    public static <T> Set<T> symmetricDifference(Set<T> set1, Set<T> set2) {
        Set<T> result = new HashSet<>();
        Set<T> tmp = new HashSet<>();
        if (set1 != null) {
            result.addAll(set1);
            tmp.addAll(set1);
        }
        if (set2 != null) {
            result.addAll(set2);
            tmp.retainAll(set2);
        }
        result.removeAll(tmp);
        return result;

    }

    public static <T> boolean isFirstSmaller(HashSet<T> set1, HashSet<T> set2, boolean equalWins) {
        if (set2.containsAll(set1)) {
            if (set2.size() > set1.size()) return true;
            return equalWins;
        }
        return false;
    }

    public static <T> Set<Set<T>> convertArraysToSets(T[][] w) {
        Set<Set<T>> result = new HashSet<>();
        for (T[] v : w) {
            result.add(new HashSet<>(Arrays.asList(v)));
        }
        return result;
    }

}

@@ -23,16 +23,50 @@
 utils;%0A%0A
+import org.workcraft.types.Pair;%0A%0A
 import j
@@ -108,16 +108,38 @@
 ashSet;%0A
+import java.util.Map;%0A
 import j
@@ -1711,10 +1711,520 @@
 %0A    %7D%0A%0A
+    public static %3CT%3E Pair%3CSet%3CT%3E, Set%3CT%3E%3E partition(Map%3CT, Boolean%3E itemToBooleanMap) %7B%0A        Set%3CT%3E trueItems = new HashSet%3C%3E();%0A        Set%3CT%3E falseItems = new HashSet%3C%3E();%0A        for (T item : itemToBooleanMap.keySet()) %7B%0A            Boolean value = itemToBooleanMap.get(item);%0A            if (value != null) %7B%0A                Set%3CT%3E partitionItems = value ? trueItems : falseItems;%0A                partitionItems.add(item);%0A            %7D%0A        %7D%0A        return Pair.of(trueItems, falseItems);%0A    %7D%0A%0A
 %7D%0A

Add function to partition set by boolean attribute