RingRange { public boolean encloses(RingRange other) { if (!isWrapping()) { return !other.isWrapping() && SegmentGenerator.greaterThanOrEqual(other.start, start) && SegmentGenerator.lowerThanOrEqual(other.end, end); } else { return (!other.isWrapping() && (SegmentGenerator.greaterThanOrEqual(other.start, start) || SegmentGenerator.lowerThanOrEqual(other.end, end))) || (SegmentGenerator.greaterThanOrEqual(other.start, start) && SegmentGenerator.lowerThanOrEqual(other.end, end)); } } RingRange(BigInteger start, BigInteger end);  RingRange(String... range); BigInteger getStart(); BigInteger getEnd(); BigInteger span(BigInteger ringSize); boolean encloses(RingRange other); @JsonIgnore boolean isWrapping(); @Override String toString(); static RingRange merge(List<RingRange> ranges); static final Comparator<RingRange> START_COMPARATOR; }
@Test public void testEncloses() throws Exception { RingRange r0To20 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(20L)); RingRange r5To15 = new RingRange(BigInteger.valueOf(5L), BigInteger.valueOf(15L)); assertTrue(r0To20.encloses(r5To15)); RingRange r5To25 = new RingRange(BigInteger.valueOf(5L), BigInteger.valueOf(25L)); assertFalse(r0To20.encloses(r5To25)); RingRange r190To25 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(25L)); assertFalse(r0To20.encloses(r190To25)); RingRange r0To15 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(15L)); assertTrue(r0To20.encloses(r0To15)); RingRange r190To15 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(15L)); assertFalse(r0To20.encloses(r190To15)); RingRange r190To0 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(0L)); assertFalse(r0To20.encloses(r190To0)); RingRange r15To20 = new RingRange(BigInteger.valueOf(15L), BigInteger.valueOf(20L)); assertTrue(r0To20.encloses(r15To20)); assertTrue(r0To20.encloses(r0To20)); RingRange r20To25 = new RingRange(BigInteger.valueOf(20L), BigInteger.valueOf(25L)); assertFalse(r0To20.encloses(r20To25)); RingRange r190To20 = new RingRange(BigInteger.valueOf(190L), BigInteger.valueOf(20L)); assertFalse(r190To20.encloses(r5To25)); RingRange r200To10 = new RingRange(BigInteger.valueOf(200L), BigInteger.valueOf(10L)); assertTrue(r190To20.encloses(r200To10)); RingRange r0To2 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(2L)); RingRange r5To190 = new RingRange(BigInteger.valueOf(5L), BigInteger.valueOf(190L)); assertFalse(r0To2.encloses(r5To190)); RingRange r15To5 = new RingRange(BigInteger.valueOf(15L), BigInteger.valueOf(5L)); RingRange r0To0 = new RingRange(BigInteger.valueOf(0L), BigInteger.valueOf(0L)); assertTrue(r0To0.encloses(r0To20)); assertTrue(r0To0.encloses(r15To20)); assertFalse(r0To0.encloses(r15To5)); assertTrue(r0To0.encloses(r190To0)); assertFalse(r0To20.encloses(r0To0)); assertFalse(r15To20.encloses(r0To0)); assertFalse(r5To15.encloses(r0To0)); assertFalse(r190To0.encloses(r0To0)); }