Range implements Comparable<Range> { public static boolean containsReaderPosition(long writerStart, long writerEnd, long readerPosition, BufferPositionParser parser) { if (readerPosition < 0 ) return false; if (parser.bufferGenId(readerPosition) < parser.bufferGenId(writerStart)) { long fakeReaderPos = parser.setGenId(readerPosition, parser.bufferGenId(writerStart)); return writerStart <= fakeReaderPos && fakeReaderPos < writerEnd; } else { return writerStart <= readerPosition && readerPosition < writerEnd; } } Range(long startOffset, long endOffset);  Range(); boolean contains(long someOffset); static boolean containsReaderPosition(long writerStart,
												long writerEnd,
												long readerPosition,
												BufferPositionParser parser); static boolean containsIgnoreGenId(long start,
			                                  long end,
			                                  long offset,
			                                  BufferPositionParser parser); static boolean contains(long start, long end, long someOffset); boolean intersects(Range intersectedRange); @Override int compareTo(Range comparedRange); String toString(BufferPositionParser parser); @Override String toString(); long getStart(); void setStart(long start); long getEnd(); void setEnd(long end); @Override boolean equals(Object obj); @Override int hashCode(); public long start; public long end; }
@Test public void testContainsReaderPosition() { BufferPositionParser parser = new BufferPositionParser(100240000 ,1); AssertJUnit.assertFalse(Range.containsReaderPosition(14551, 14551, 109, parser)); AssertJUnit.assertTrue(Range.containsReaderPosition(parser.setGenId(100, 0), parser.setGenId(200,2), parser.setGenId(100,1), parser)); }
@Test public void testContainsReaderPositionDiffGenId() { BufferPositionParser parser = new BufferPositionParser(100240000, 3); long start = parser.setGenId(0, 1); start = parser.setIndex(start, 0); start = parser.setOffset(start, 0); long end = parser.setGenId(0, 2); end = parser.setIndex(end, 0); end = parser.setOffset(end, 0); long offset = parser.setGenId(0, 1); offset = parser.setIndex(offset, 2); offset = parser.setOffset(offset, 10); AssertJUnit.assertTrue(Range.containsReaderPosition(start, end, offset, parser)); AssertJUnit.assertTrue(Range.containsReaderPosition(start, end, start, parser)); AssertJUnit.assertFalse(Range.containsReaderPosition(start, end, end, parser)); }