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

Method intersection

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

Returns an unmodifiable view of the intersection of two sets. The returned set contains all elements that are contained by both backing sets. The iteration order of the returned set matches that of set1. Results are undefined if set1 and set2 are sets based on diff

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

Source from the content-addressed store, hash-verified

656 * <p>This is unfortunate, but should come up only very rarely.
657 */
658 public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2) {
659 checkNotNull(set1, "set1");
660 checkNotNull(set2, "set2");
661
662 final Predicate<Object> inSet2 = Predicates.in(set2);
663 return new SetView<E>() {
664 @Override
665 public Iterator<E> iterator() {
666 return Iterators.filter(set1.iterator(), inSet2);
667 }
668
669 @Override
670 public int size() {
671 return Iterators.size(iterator());
672 }
673
674 @Override
675 public boolean isEmpty() {
676 return !iterator().hasNext();
677 }
678
679 @Override
680 public boolean contains(Object object) {
681 return set1.contains(object) && set2.contains(object);
682 }
683
684 @Override
685 public boolean containsAll(Collection<?> collection) {
686 return set1.containsAll(collection) && set2.containsAll(collection);
687 }
688 };
689 }
690
691 /**
692 * Returns an unmodifiable <b>view</b> of the difference of two sets. The

Callers 15

createElementSetMethod · 0.95
intersectsMethod · 0.45
subMapMethod · 0.45
subMapMethod · 0.45
subMapMethod · 0.45
getMethod · 0.45
computeNextMethod · 0.45
enclosesMethod · 0.45
rangeContainingMethod · 0.45
removeMethod · 0.45
subRangeSetMethod · 0.45
getEntryMethod · 0.45

Calls 2

inMethod · 0.95
checkNotNullMethod · 0.45

Tested by

no test coverage detected