package jalview.util; import java.util.Set; public class SetUtils { /** * Returns the count of things that are in one or other of two sets but not in * both. The sets are not modified. * * @param set1 * @param set2 * @return */ public static int countDisjunction(Set set1, Set set2) { if (set1 == null) { return set2 == null ? 0 : set2.size(); } if (set2 == null) { return set1.size(); } int size1 = set1.size(); int size2 = set2.size(); Set smallerSet = size1 < size2 ? set1 : set2; Set largerSet = (smallerSet == set1 ? set2 : set1); int inCommon = 0; for (Object k : smallerSet) { if (largerSet.contains(k)) { inCommon++; } } int notInCommon = (size1 - inCommon) + (size2 - inCommon); return notInCommon; } }