public IntervalSet negate() {
    List<IntervalSet> negations = new ArrayList<>();

    for (Interval i : getIntervals()) {
      negations.add(i.negate());
    }

    if (negations.isEmpty()) {
      return NEVER;
    }

    if (negations.size() == 1) {
      return negations.get(0);
    }

    return IntervalUtils.intersect(negations);
  }
@Test
  public void negate() {
    for (int i = 0; i < 100; i++) {
      List<Long> sortedTimes =
          ThreadLocalRandom.current().longs(1, Long.MAX_VALUE - 1).distinct().limit(2).sorted()
              .boxed().collect(Collectors.toList());
      long startMs = sortedTimes.get(0);
      long endMs = sortedTimes.get(1);

      Interval interval = Interval.between(startMs, endMs);
      List<Interval> negationList = new IntervalSet(interval).negate().getIntervals();

      Assert.assertTrue(negationList.size() == 2);
      Assert.assertTrue(Sets.newHashSet(negationList)
          .containsAll(Arrays.asList(Interval.before(startMs), Interval.after(endMs))));

      // negate again
      List<Interval> negationList2 = new IntervalSet(negationList).negate().getIntervals();
      Assert.assertTrue(negationList2.size() == 1);
      Assert.assertTrue(Sets.newHashSet(negationList2).contains(interval));
    }
  }