@Test public void testComplement() { final MarkerRange unbounded = new MarkerRange(comparator); final MarkerRange unboundedToNov1 = new MarkerRange(comparator).to(NOV_1); final MarkerRange oct12ToOct15 = new MarkerRange(comparator).from(OCT_12).to(OCT_15); final MarkerRange afterNov1ToUnbounded = new MarkerRange(comparator).fromAfter(NOV_1); TestHelpers.assertThrows("Can't find complement of unbounded range.", IllegalArgumentException.class, new Runnable() { @Override public void run() { unbounded.complement(); } }); assertEquals(afterNov1ToUnbounded, unboundedToNov1.complement()); assertEquals(unboundedToNov1, afterNov1ToUnbounded.complement()); assertEquals(unbounded, oct12ToOct15.complement()); }
public MarkerRange complement() { if (start == Boundary.NEGATIVE_INFINITY && end == Boundary.POSITIVE_INFINITY) { throw new IllegalArgumentException("Cannot find complement of unbounded range."); } if (start == Boundary.NEGATIVE_INFINITY) { Boundary newStart = new Boundary(comparator, end.bound, !end.isInclusive); Boundary newEnd = Boundary.POSITIVE_INFINITY; return new MarkerRange(comparator, newStart, newEnd); } else if (end == Boundary.POSITIVE_INFINITY) { Boundary newStart = Boundary.NEGATIVE_INFINITY; Boundary newEnd = new Boundary(comparator, start.bound, !start.isInclusive); return new MarkerRange(comparator, newStart, newEnd); } return new MarkerRange(); }
MarkerRange { public MarkerRange complement() { if (start == Boundary.NEGATIVE_INFINITY && end == Boundary.POSITIVE_INFINITY) { throw new IllegalArgumentException("Cannot find complement of unbounded range."); } if (start == Boundary.NEGATIVE_INFINITY) { Boundary newStart = new Boundary(comparator, end.bound, !end.isInclusive); Boundary newEnd = Boundary.POSITIVE_INFINITY; return new MarkerRange(comparator, newStart, newEnd); } else if (end == Boundary.POSITIVE_INFINITY) { Boundary newStart = Boundary.NEGATIVE_INFINITY; Boundary newEnd = new Boundary(comparator, start.bound, !start.isInclusive); return new MarkerRange(comparator, newStart, newEnd); } return new MarkerRange(); } }
MarkerRange { public MarkerRange complement() { if (start == Boundary.NEGATIVE_INFINITY && end == Boundary.POSITIVE_INFINITY) { throw new IllegalArgumentException("Cannot find complement of unbounded range."); } if (start == Boundary.NEGATIVE_INFINITY) { Boundary newStart = new Boundary(comparator, end.bound, !end.isInclusive); Boundary newEnd = Boundary.POSITIVE_INFINITY; return new MarkerRange(comparator, newStart, newEnd); } else if (end == Boundary.POSITIVE_INFINITY) { Boundary newStart = Boundary.NEGATIVE_INFINITY; Boundary newEnd = new Boundary(comparator, start.bound, !start.isInclusive); return new MarkerRange(comparator, newStart, newEnd); } return new MarkerRange(); } private  MarkerRange();  MarkerRange(MarkerComparator comparator); private  MarkerRange(
      MarkerComparator comparator,
      Boundary start, Boundary end); }
MarkerRange { public MarkerRange complement() { if (start == Boundary.NEGATIVE_INFINITY && end == Boundary.POSITIVE_INFINITY) { throw new IllegalArgumentException("Cannot find complement of unbounded range."); } if (start == Boundary.NEGATIVE_INFINITY) { Boundary newStart = new Boundary(comparator, end.bound, !end.isInclusive); Boundary newEnd = Boundary.POSITIVE_INFINITY; return new MarkerRange(comparator, newStart, newEnd); } else if (end == Boundary.POSITIVE_INFINITY) { Boundary newStart = Boundary.NEGATIVE_INFINITY; Boundary newEnd = new Boundary(comparator, start.bound, !start.isInclusive); return new MarkerRange(comparator, newStart, newEnd); } return new MarkerRange(); } private  MarkerRange();  MarkerRange(MarkerComparator comparator); private  MarkerRange(
      MarkerComparator comparator,
      Boundary start, Boundary end); boolean contains(Marker marker); MarkerRange from(Marker start); MarkerRange fromAfter(Marker start); MarkerRange to(Marker end); MarkerRange toBefore(Marker end); MarkerRange of(Marker partial); MarkerRange intersection(MarkerRange other); MarkerRange span(MarkerRange other); MarkerRange complement(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Boundary getStart(); Boundary getEnd(); }
MarkerRange { public MarkerRange complement() { if (start == Boundary.NEGATIVE_INFINITY && end == Boundary.POSITIVE_INFINITY) { throw new IllegalArgumentException("Cannot find complement of unbounded range."); } if (start == Boundary.NEGATIVE_INFINITY) { Boundary newStart = new Boundary(comparator, end.bound, !end.isInclusive); Boundary newEnd = Boundary.POSITIVE_INFINITY; return new MarkerRange(comparator, newStart, newEnd); } else if (end == Boundary.POSITIVE_INFINITY) { Boundary newStart = Boundary.NEGATIVE_INFINITY; Boundary newEnd = new Boundary(comparator, start.bound, !start.isInclusive); return new MarkerRange(comparator, newStart, newEnd); } return new MarkerRange(); } private  MarkerRange();  MarkerRange(MarkerComparator comparator); private  MarkerRange(
      MarkerComparator comparator,
      Boundary start, Boundary end); boolean contains(Marker marker); MarkerRange from(Marker start); MarkerRange fromAfter(Marker start); MarkerRange to(Marker end); MarkerRange toBefore(Marker end); MarkerRange of(Marker partial); MarkerRange intersection(MarkerRange other); MarkerRange span(MarkerRange other); MarkerRange complement(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Boundary getStart(); Boundary getEnd();  }