@Test public void testMapOfDisjointIntervals() { for (int intervalSize = 1; intervalSize <= 5; intervalSize++) { List<Interval> control = new ArrayList<Interval>(); SortedMap<Interval, Interval> map = new TreeMap<Interval, Interval>(); for (int i = 0; i < 100; i++) { Interval interval = interval(i * intervalSize, (i + 1) * intervalSize - 1); control.add(interval); map.put(interval, interval); } Assert.assertEquals(control.size(), map.size()); Iterator<Interval> controlScan = control.iterator(); Iterator<Interval> mapScan = map.keySet().iterator(); while (controlScan.hasNext() && mapScan.hasNext()) { Interval controlInterval = controlScan.next(); Interval mapInterval = mapScan.next(); Assert.assertEquals(controlInterval, mapInterval); mapInterval = map.get(controlInterval); Assert.assertEquals(controlInterval, mapInterval); } Assert.assertTrue(!controlScan.hasNext()); Assert.assertTrue(!mapScan.hasNext()); } }
public Interval(long x) { this(x, x); }
Interval implements Comparable<Interval> { public Interval(long x) { this(x, x); } }
Interval implements Comparable<Interval> { public Interval(long x) { this(x, x); } Interval(long x);  Interval(long min, long max); }
Interval implements Comparable<Interval> { public Interval(long x) { this(x, x); } Interval(long x);  Interval(long min, long max); String toString(); int compareTo(Interval that); long min(); long max(); }
Interval implements Comparable<Interval> { public Interval(long x) { this(x, x); } Interval(long x);  Interval(long min, long max); String toString(); int compareTo(Interval that); long min(); long max();  }