@Test public void disjunction() { final SetView<Integer> set = SetUtils.disjunction(setA, setB); assertEquals(4, set.size()); assertTrue(set.contains(1)); assertTrue(set.contains(2)); assertTrue(set.contains(6)); assertTrue(set.contains(7)); assertFalse(set.contains(3)); assertFalse(set.contains(4)); assertFalse(set.contains(5)); final Set<Integer> set2 = SetUtils.disjunction(setA, SetUtils.<Integer>emptySet()); assertEquals(setA, set2); try { SetUtils.disjunction(setA, null); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } try { SetUtils.disjunction(null, setA); fail("Expecting NullPointerException"); } catch (NullPointerException npe) { } }
public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } private  SetUtils(); }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } private  SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set,
                                            final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set,
                                                       final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set,
                                                        final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set,
                                                          final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set,
                                                           final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); }
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.contains(o) ^ b.contains(o); } @Override public Iterator<E> createIterator() { return IteratorUtils.chainedIterator(aMinusB.iterator(), bMinusA.iterator()); } @Override public boolean isEmpty() { return aMinusB.isEmpty() && bMinusA.isEmpty(); } @Override public int size() { return aMinusB.size() + bMinusA.size(); } }; } private  SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2); static int hashCodeForSet(final Collection<T> set); static Set<E> newIdentityHashSet(); static Set<E> synchronizedSet(final Set<E> set); static Set<E> unmodifiableSet(final Set<? extends E> set); static Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate); static Set<E> transformedSet(final Set<E> set,
                                            final Transformer<? super E, ? extends E> transformer); static Set<E> orderedSet(final Set<E> set); static SortedSet<E> synchronizedSortedSet(final SortedSet<E> set); static SortedSet<E> unmodifiableSortedSet(final SortedSet<E> set); static SortedSet<E> predicatedSortedSet(final SortedSet<E> set,
                                                       final Predicate<? super E> predicate); static SortedSet<E> transformedSortedSet(final SortedSet<E> set,
                                                        final Transformer<? super E, ? extends E> transformer); static SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set); static SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set,
                                                          final Predicate<? super E> predicate); static SortedSet<E> transformedNavigableSet(final NavigableSet<E> set,
                                                           final Transformer<? super E, ? extends E> transformer); static SetView<E> union(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b); static SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b); @SuppressWarnings("rawtypes")
    static final SortedSet EMPTY_SORTED_SET; }