/** * Returns whether the sets are disjoint. * * <p>XXX bogus for empty sets */ public static boolean areDisjoint(Set<?>... ss) { if (ss == null || ss.length == 0) return true; int elementCount = 0; for (Set<?> set : ss) { elementCount += set.size(); } return CollectionsExt.union(ss).size() == elementCount; }
/** * Creates a set of all sequences of length max of objects. The order matters and elements may be * repeated. The set is grouped by the number of objects in the array. The result is a map from * arities to object sequences. * * <p>NOTE: This is done with arrays rather than lists because in JOE we don't want to execute any * code of the objects. */ public static Map<Integer, Set<Object[]>> createPerArityGroups(Object[] objects, int max) { Map<Integer, Set<Object[]>> result = new LinkedHashMap<Integer, Set<Object[]>>(); result.put(0, Collections.singleton(new Object[0])); for (int i = 1; i <= max; i++) { Set<Object[]> newSet = new LinkedHashSet<Object[]>(); // add each object to each one smaller for (Object[] oneSmaller : result.get(i - 1)) { for (Object object : objects) { newSet.add(CollectionsExt.addToArray(oneSmaller, object)); } } result.put(i, newSet); } return result; }