@Test public void shouldNotExcludeIfOtherIsBefore() { R range = getTestRange(from("10"), to("20")); R other = getTestRange(from("2"), to("9")); List<R> result = Collections.singletonList(range); assertEquals(result, range.exclude(other)); }
@SuppressWarnings({"unchecked"}) @Override public List<R> exclude(R other) { if (!overlaps(other)) { return Collections.singletonList((R) this); } else if (other.contains((R) this)) { return Collections.emptyList(); } else if (!this.contains(other.start()) && this.contains(other.end())) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.contains(other.start()) && !this.contains(other.end())) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { if (this.hasSameStart(other)) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.hasSameEnd(other)) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { ArrayList<R> rs = new ArrayList<R>(2); rs.add(newInstance(this.start, other.start().previous())); rs.add(newInstance(other.end().next(), this.end)); return rs; } } }
AbstractRange implements Range<C, R> { @SuppressWarnings({"unchecked"}) @Override public List<R> exclude(R other) { if (!overlaps(other)) { return Collections.singletonList((R) this); } else if (other.contains((R) this)) { return Collections.emptyList(); } else if (!this.contains(other.start()) && this.contains(other.end())) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.contains(other.start()) && !this.contains(other.end())) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { if (this.hasSameStart(other)) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.hasSameEnd(other)) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { ArrayList<R> rs = new ArrayList<R>(2); rs.add(newInstance(this.start, other.start().previous())); rs.add(newInstance(other.end().next(), this.end)); return rs; } } } }
AbstractRange implements Range<C, R> { @SuppressWarnings({"unchecked"}) @Override public List<R> exclude(R other) { if (!overlaps(other)) { return Collections.singletonList((R) this); } else if (other.contains((R) this)) { return Collections.emptyList(); } else if (!this.contains(other.start()) && this.contains(other.end())) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.contains(other.start()) && !this.contains(other.end())) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { if (this.hasSameStart(other)) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.hasSameEnd(other)) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { ArrayList<R> rs = new ArrayList<R>(2); rs.add(newInstance(this.start, other.start().previous())); rs.add(newInstance(other.end().next(), this.end)); return rs; } } } protected  AbstractRange(C start, C end); }
AbstractRange implements Range<C, R> { @SuppressWarnings({"unchecked"}) @Override public List<R> exclude(R other) { if (!overlaps(other)) { return Collections.singletonList((R) this); } else if (other.contains((R) this)) { return Collections.emptyList(); } else if (!this.contains(other.start()) && this.contains(other.end())) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.contains(other.start()) && !this.contains(other.end())) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { if (this.hasSameStart(other)) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.hasSameEnd(other)) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { ArrayList<R> rs = new ArrayList<R>(2); rs.add(newInstance(this.start, other.start().previous())); rs.add(newInstance(other.end().next(), this.end)); return rs; } } } 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> { @SuppressWarnings({"unchecked"}) @Override public List<R> exclude(R other) { if (!overlaps(other)) { return Collections.singletonList((R) this); } else if (other.contains((R) this)) { return Collections.emptyList(); } else if (!this.contains(other.start()) && this.contains(other.end())) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.contains(other.start()) && !this.contains(other.end())) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { if (this.hasSameStart(other)) { return Collections.singletonList(newInstance(other.end().next(), this.end)); } else if (this.hasSameEnd(other)) { return Collections.singletonList(newInstance(this.start, other.start().previous())); } else { ArrayList<R> rs = new ArrayList<R>(2); rs.add(newInstance(this.start, other.start().previous())); rs.add(newInstance(other.end().next(), this.end)); return rs; } } } 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();  }