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

Method intersection

output/java_guava/1.4.17/Sets.java:699–730  ·  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

697
698
699 public static <E> SetView<E> intersection(
700 final Set<E> set1, final Set<?> set2) {
701 checkNotNull(set1, "set1");
702 checkNotNull(set2, "set2");
703 final Predicate<Object> inSet2 = Predicates.in(set2);
704 return new SetView<E>() {
705 @Override
706 public Iterator<E> iterator() {
707 return Iterators.filter(set1.iterator(), inSet2);
708 }
709
710 @Override
711 public int size() {
712 return Iterators.size(iterator());
713 }
714
715 @Override
716 public boolean isEmpty() {
717 return !iterator().hasNext();
718 }
719
720 @Override
721 public boolean contains(Object object) {
722 return set1.contains(object) && set2.contains(object);
723 }
724
725 @Override
726 public boolean containsAll(Collection<?> collection) {
727 return set1.containsAll(collection) && set2.containsAll(collection);
728 }
729 };
730 }
731
732 /**
733 * 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