/** * Returns true if the {@code other} subrange is <b>fully</b> contained within this subrange. An * empty {@code other} is trivially considered to be contained within any subrange. */ public boolean contains(@Nonnull SubRange other) { return other.isEmpty() || (_start <= other.getStart() && _end >= other.getEnd()); }
/** Exclude a {@link SubRange} */ public Builder excluding(SubRange range) { if (!range.isEmpty()) { _excluding.add( Range.closed(range.getStart(), range.getEnd()).canonical(DiscreteDomain.integers())); } return this; }
/** Include a {@link SubRange} */ public Builder including(SubRange range) { if (!range.isEmpty()) { _including.add( Range.closed(range.getStart(), range.getEnd()).canonical(DiscreteDomain.integers())); } return this; }
@Test public void testEmptyRange() { SubRange range = new SubRange(3, 1); assertThat(range.isEmpty(), equalTo(true)); assertThat(range.getStart(), equalTo(3)); assertThat(range.getEnd(), equalTo(1)); assertThat(range.includes(1), equalTo(false)); assertThat(range.includes(2), equalTo(false)); assertThat(range.includes(3), equalTo(false)); }