MCPcopy Create free account
hub / github.com/antlr/codebuff / difference

Method difference

corpus/java/training/guava/collect/Sets.java:702–728  ·  view source on GitHub ↗

Returns an unmodifiable view of the difference of two sets. The returned set contains all elements that are contained by set1 and not contained by set2. set2 may also contain elements not present in set1; these are simply ignored. The iteration order of the ret

(final Set<E> set1, final Set<?> set2)

Source from the content-addressed store, hash-verified

700 * and the keySet of an {@code IdentityHashMap} all are).
701 */
702 public static <E> SetView<E> difference(final Set<E> set1, final Set<?> set2) {
703 checkNotNull(set1, "set1");
704 checkNotNull(set2, "set2");
705
706 final Predicate<Object> notInSet2 = Predicates.not(Predicates.in(set2));
707 return new SetView<E>() {
708 @Override
709 public Iterator<E> iterator() {
710 return Iterators.filter(set1.iterator(), notInSet2);
711 }
712
713 @Override
714 public int size() {
715 return Iterators.size(iterator());
716 }
717
718 @Override
719 public boolean isEmpty() {
720 return set2.containsAll(set1);
721 }
722
723 @Override
724 public boolean contains(Object element) {
725 return set1.contains(element) && !set2.contains(element);
726 }
727 };
728 }
729
730 /**
731 * Returns an unmodifiable <b>view</b> of the symmetric difference of two

Callers 3

unionMethod · 0.95
parallelEdgesMethod · 0.95
adjacentEdgesMethod · 0.95

Calls 3

notMethod · 0.95
inMethod · 0.95
checkNotNullMethod · 0.45

Tested by

no test coverage detected