code: private void checkRange(long index) {
      Assert.indexNot(isEmpty(), "segment is empty");
      Assert.indexNot(index < firstIndex(), index + " is less than the first index in the segment");
      Assert.indexNot(index > lastIndex(), index + " is greater than the last index in the segment");
    }
docs: Checks the range of the given index.
  
  @throws IndexOutOfBoundsException if the {@code index} is invalid for the segment