code: public synchronized Segment segment(long index) {
      assertOpen();
      // Check if the current segment contains the given index first in order to prevent an unnecessary map lookup.
      if (currentSegment != null && currentSegment.validIndex(index))
        return currentSegment;
  
      // If the index is in another segment, get the entry with the next lowest first index.
      Map.Entry<Long, Segment> segment = segments.floorEntry(index);
      return segment != null ? segment.getValue() : null;
    }
docs: Returns the segment for the given index.
  
  @param index The index for which to return the segment.
  @throws IllegalStateException if the segment manager is not open