@Test public void overlapForKnownValues() { Assert.assertEquals(1, TestUtils.ZERO_ONE.overlap(TestUtils.ZERO_ONE)); Assert.assertEquals(1, TestUtils.ZERO_ONE.overlap(TestUtils.ZERO_TEN)); Assert.assertEquals(1, TestUtils.ZERO_TEN.overlap(TestUtils.ZERO_ONE)); Assert.assertEquals(0, TestUtils.ZERO_ONE.overlap(TestUtils.ONE_TEN)); Assert.assertEquals(0, TestUtils.ONE_TEN.overlap(TestUtils.ZERO_ONE)); Assert.assertEquals(9, TestUtils.ZERO_TEN.overlap(TestUtils.ONE_TEN)); Assert.assertEquals(9, TestUtils.ONE_TEN.overlap(TestUtils.ZERO_TEN)); }
long overlap(LongRange other) { if (start >= other.end | end <= other.start) { return 0; } else { if (start < other.start | end > other.end) { return Math.min(end, other.end) - Math.max(start, other.start); } else { return end - start; } } }
LongRange implements Range<Long, LongContent> { long overlap(LongRange other) { if (start >= other.end | end <= other.start) { return 0; } else { if (start < other.start | end > other.end) { return Math.min(end, other.end) - Math.max(start, other.start); } else { return end - start; } } } }
LongRange implements Range<Long, LongContent> { long overlap(LongRange other) { if (start >= other.end | end <= other.start) { return 0; } else { if (start < other.start | end > other.end) { return Math.min(end, other.end) - Math.max(start, other.start); } else { return end - start; } } } LongRange(long start, long end); }
LongRange implements Range<Long, LongContent> { long overlap(LongRange other) { if (start >= other.end | end <= other.start) { return 0; } else { if (start < other.start | end > other.end) { return Math.min(end, other.end) - Math.max(start, other.start); } else { return end - start; } } } LongRange(long start, long end); @Override Long getStart(); @Override Long getEnd(); @Override boolean contains(Long point); LongContent length(); static LongRange of(long start, long end); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }
LongRange implements Range<Long, LongContent> { long overlap(LongRange other) { if (start >= other.end | end <= other.start) { return 0; } else { if (start < other.start | end > other.end) { return Math.min(end, other.end) - Math.max(start, other.start); } else { return end - start; } } } LongRange(long start, long end); @Override Long getStart(); @Override Long getEnd(); @Override boolean contains(Long point); LongContent length(); static LongRange of(long start, long end); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }