@Test public void shouldMergeConsecutiveWhenOtherOnStart() { R range = getTestRange(from("10"), to("20")); R other = getTestRange(from("10"), to("10")); R expected = getTestRange(from("10"), to("20")); assertEquals(expected, range.merge(other)); assertEquals(expected, other.merge(range)); }
@Override public R merge(R other) { Validate.isTrue(this.overlaps(other) || this.isConsecutive(other), "Merge is only possible for overlapping or consecutive ranges"); C min = min(this.start, other.start()); C max = max(this.end, other.end()); return newInstance(min, max); }
AbstractRange implements Range<C, R> { @Override public R merge(R other) { Validate.isTrue(this.overlaps(other) || this.isConsecutive(other), "Merge is only possible for overlapping or consecutive ranges"); C min = min(this.start, other.start()); C max = max(this.end, other.end()); return newInstance(min, max); } }
AbstractRange implements Range<C, R> { @Override public R merge(R other) { Validate.isTrue(this.overlaps(other) || this.isConsecutive(other), "Merge is only possible for overlapping or consecutive ranges"); C min = min(this.start, other.start()); C max = max(this.end, other.end()); return newInstance(min, max); } protected  AbstractRange(C start, C end); }
AbstractRange implements Range<C, R> { @Override public R merge(R other) { Validate.isTrue(this.overlaps(other) || this.isConsecutive(other), "Merge is only possible for overlapping or consecutive ranges"); C min = min(this.start, other.start()); C max = max(this.end, other.end()); return newInstance(min, max); } protected  AbstractRange(C start, C end); @Override C start(); @Override C end(); @Override boolean contains(R other); @Override boolean contains(C value); @Override boolean overlaps(R other); @Override boolean isConsecutive(R other); @Override boolean isEmpty(); @Override R merge(R other); @Override R intersection(R other); @SuppressWarnings({"unchecked"}) @Override List<R> exclude(R other); @Override boolean isSameRange(R other); @Override String toString(); @Override Iterator<C> iterator(); @Override final boolean equals(Object o); @Override final int hashCode(); }
AbstractRange implements Range<C, R> { @Override public R merge(R other) { Validate.isTrue(this.overlaps(other) || this.isConsecutive(other), "Merge is only possible for overlapping or consecutive ranges"); C min = min(this.start, other.start()); C max = max(this.end, other.end()); return newInstance(min, max); } protected  AbstractRange(C start, C end); @Override C start(); @Override C end(); @Override boolean contains(R other); @Override boolean contains(C value); @Override boolean overlaps(R other); @Override boolean isConsecutive(R other); @Override boolean isEmpty(); @Override R merge(R other); @Override R intersection(R other); @SuppressWarnings({"unchecked"}) @Override List<R> exclude(R other); @Override boolean isSameRange(R other); @Override String toString(); @Override Iterator<C> iterator(); @Override final boolean equals(Object o); @Override final int hashCode();  }