Compute the set intersection of two sets.

@param first First set
@param second Second set
@return intersection
353133
public static ModifiableDBIDs intersection(DBIDs first, DBIDs second) {
    // If exactly one is a Set, use it as second parameter.
    if(second instanceof SetDBIDs) {
      if(!(first instanceof SetDBIDs)) {
        return internalIntersection(first, second);
      }
    }
    else if(first instanceof SetDBIDs) {
      return internalIntersection(second, first);
    }
    // Both are the same type: both set or both non set.
    // Smaller goes first.
    return first.size() <= second.size() ? internalIntersection(first, second) : internalIntersection(second, first);
  }
96896
def intersection(self, *iterables):
        
        comb = self._set.intersection(*iterables)
        new_set = self.__class__(key=self._key, load=self._load, _set=comb)
        return new_set
1148867
def intersection(other)
      raise(ISO8601::Errors::IntervalError, "The intervals are disjoint") \
        if disjoint?(other) && other.disjoint?(self)

      return self if subset?(other)
      return other if other.subset?(self)

      a, b = sort_pair(self, other)
      self.class.from_datetimes(b.first, a.last)
    end
1051360
public static <E> Set<E> intersection(Set<E> s1, Set<E> s2) {
    Set<E> s = new HashSet<E>();
    s.addAll(s1);
    s.retainAll(s2);
    return s;
  }
36003
public static <E> Set<E> union(Set<E> s1, Set<E> s2) {
    Set<E> s = new HashSet<E>();
    s.addAll(s1);
    s.addAll(s2);
    return s;
  }
571469
public static <T> List<T> intersection(List<T> arr1, int start1, int end1, List<T> arr2,
                                           int start2, int end2) {
        if (start1 > end1 || start2 > end2) {
            throw new IllegalArgumentException("起始位置必须小于等于结束位置");
        }
        if (start1 == end1 || start2 == end2) {
            return Collections.emptyList();
        }

        List<T> list = new ArrayList<>();
        for (int i = start1; i < end1; i++) {
            int index = arr2.indexOf(arr1.get(i));
            if (index < end2 && index >= start2) {
                list.add(arr1.get(i));
            }
        }
        return list;
    }
422910
public static <F, S> Pair<F, S> of(F first, S second) {
        if (first == null || second == null) {
            throw new IllegalArgumentException("Pair.of requires non null values.");
        }
        return new Pair<F, S>(first, second);
    }
391096
def intersection(self, *iterables):
        
        comb = self._set.intersection(*iterables)
        return self._fromset(comb, key=self._key)
786560
public static boolean intersects(Geometry one, Geometry two) {
		if (one == null || two == null || isEmpty(one) || isEmpty(two)) {
			return false;
		}
		if (Geometry.POINT.equals(one.getGeometryType())) {
			return intersectsPoint(one, two);
		} else if (Geometry.LINE_STRING.equals(one.getGeometryType())) {
			return intersectsLineString(one, two);
		} else if (Geometry.MULTI_POINT.equals(one.getGeometryType())
				|| Geometry.MULTI_LINE_STRING.equals(one.getGeometryType())) {
			return intersectsMultiSomething(one, two);
		}
		List<Coordinate> coords1 = new ArrayList<Coordinate>();
		List<Coordinate> coords2 = new ArrayList<Coordinate>();
		getAllCoordinates(one, coords1);
		getAllCoordinates(two, coords2);

		for (int i = 0; i < coords1.size() - 1; i++) {
			for (int j = 0; j < coords2.size() - 1; j++) {
				if (MathService.intersectsLineSegment(coords1.get(i), coords1.get(i + 1), coords2.get(j),
						coords2.get(j + 1))) {
					return true;
				}
			}
		}
		return false;
	}
1184467
public Range<T> intersectionWith(Range<T> other) {
    if (!this.isOverlappedBy(other)) { throw new IllegalArgumentException(String.format(
        "Cannot calculate intersection with non-overlapping range %s", other)); }
    if (this.equals(other)) { return this; }
    T min = this.comparator.compare(this.min, other.min) < 0 ? other.min : this.min;
    T max = this.comparator.compare(this.max, other.max) < 0 ? this.max : other.max;
    return between(min, max, this.comparator);
  }
1135948
function intersection( arr1, arr2 ){
	var rtn = [];

	if ( arr1.length > arr2.length ){
		let t = arr1;

		arr1 = arr2;
		arr2 = t;
	}

	for( let i = 0, c = arr1.length; i < c; i++ ){
		let d = arr1[i];

		if ( arr2.indexOf(d) !== -1 ){
			rtn.push( d );
		}
	}

	return rtn;
}
150346
function(or1, or2) {
			var d1 = set.difference(or1, or2.values[0]);
			var d2 = set.difference(or1, or2.values[1]);
			return set.intersection(d1, d2);
		}
1038661
public static IntSet difference (IntSet set1, IntSet set2)
    {
        return and(set1, notView(set2));
    }
1334674
private List<Period> _Intersect( List<Period> periods1, List<Period> periods2 )
	{
		List<Period> result = new ArrayList<Period>();

		int count1 = periods1.size();
		int count2 = periods2.size();

		int i = 0;
		int j = 0;

		while( i < count1 && j < count2 )
		{
			// one of the periods begins after the end of the other
			if( periods1.get( i ).getFrom().compareTo( periods2.get( j ).getTo() ) > 0 )
			{ // period 1 begins after period 2 finishes => period2 is
				// eliminated !
				j++;
			}
			else if( periods2.get( j ).getFrom().compareTo( periods1.get( i ).getTo() ) > 0 )
			{ // period 2 begins after end of period 1 => period 1 is eliminated
				// !
				i++;
			}

			// after that test, we can assume there is a non-void intersection
			else
			{
				// result[] = array( max($periods1[$i][0],$periods2[$j][0]),
				// min($periods1[$i][1],$periods2[$j][1]) );
				result.add( new Period( CalendarFunctions.max_date( periods1.get( i ).getFrom(), periods2.get( j ).getFrom() ), CalendarFunctions.min_date( periods1.get( i ).getTo(), periods2.get( j ).getTo() ) ) );

				if( periods1.get( i ).getTo().compareTo( periods2.get( j ).getTo() ) > 0 )
					j++;
				else
					i++;
			}
		}

		return result;
	}
1154539
public static boolean existPairwiseIntersections(Collection<Set<String>> sets) {
		// Determine all possible pairs of sets
		List<List<Set<String>>> setPairs = ListUtils.getKElementaryLists(new ArrayList<Set<String>>(sets), 2);
		for (Iterator<List<Set<String>>> iter = setPairs.iterator(); iter.hasNext();) {
			Set<String> intersection = SetUtils.intersection(iter.next());
			if (!intersection.isEmpty()) {
				return true;
			}
		}
		return false;
	}
309734
public static <E> Set<E> union(final Set<? extends E> set1, final Set<? extends E> set2) {
        checkArgumentNotNull(set1, "set1");
        checkArgumentNotNull(set2, "set2");

        // Set 2 minus set 1
        final Set<E> difference = new HashSet<>(set2);
        difference.removeAll(set1);
        // Following stream does not compile on some JDKs
        // See also https://bugs.openjdk.java.net/browse/JDK-8051443
        // set2.stream().filter((e) -> !set1.contains(e)).collect(Collectors.toSet());

        return new AbstractSet<E>() {

            @Override
            public Iterator<E> iterator() {
                final Iterator<E> iterator = Iterators.concat(ImmutableList.of(set1.iterator(), difference.iterator()).iterator());
                // Remove operation is not supported by default
                return new Iterator<E>() {
                    @Override
                    public boolean hasNext() {
                        return iterator.hasNext();
                    }

                    @Override
                    public E next() {
                        return iterator.next();
                    }
                };
            }

            @Override
            public int size() {
                return set1.size() + difference.size();
            }

            @Override
            public boolean isEmpty() {
                return set1.isEmpty() && difference.isEmpty();
            }

            @Override
            public boolean contains(Object o) {
                return set1.contains(o) || difference.contains(o);
            }
        };
    }
172777
public Rectangle intersection(Rectangle other) {
		int left = Math.max(this.left, other.left);
		int top = Math.max(this.top, other.top);
		int right = Math.min(this.right, other.right);
		int bottom = Math.min(this.bottom, other.bottom);
		if (right >= left && bottom >= top) {
			int height = bottom - top;
			int width = right - left;
			return new Rectangle(top, left, bottom, right, width, height);
		} else {
			return null;
		}
	}