public IntervalSet intersect(IntervalSet other) {
    List<Interval> intersection = new ArrayList<>(2);
    for (Interval int1 : getIntervals()) {
      for (Interval int2 : other.getIntervals()) {
        Interval i = int1.intersect(int2);
        if (i.isValid()) {
          intersection.add(i);
        }
      }
    }
    if (intersection.isEmpty()) {
      return NEVER;
    }
    return new IntervalSet(IntervalUtils.normalize(intersection));
  }
@Test
  public void intersect() {
    for (int i = 0; i < 100; i++) {
      List<Long> sortedTimes =
          ThreadLocalRandom.current().longs(0, Long.MAX_VALUE).distinct().limit(4).sorted()
              .boxed().collect(Collectors.toList());
      Interval int1 = Interval.between(sortedTimes.get(0), sortedTimes.get(2));
      Interval int2 = Interval.between(sortedTimes.get(1), sortedTimes.get(3));

      IntervalSet is = new IntervalSet(int1).intersect(new IntervalSet(int2));
      Set<Interval> s = Sets.newHashSet(is.getIntervals());
      Assert.assertEquals(1, s.size());
      Assert.assertTrue(s.contains(Interval.between(sortedTimes.get(1), sortedTimes.get(2))));

      is = new IntervalSet(Interval.after(sortedTimes.get(2)));
      Assert.assertFalse(is.intersect(is.negate()).isValid());

      is = new IntervalSet(Interval.between(sortedTimes.get(1), sortedTimes.get(2)));
      Assert.assertFalse(is.intersect(is.negate()).isValid());
    }
  }