code: public synchronized void replaceSegments(Collection<Segment> segments, Segment segment) {
      // Update the segment descriptor and lock the segment.
      segment.descriptor().update(System.currentTimeMillis());
      segment.descriptor().lock();
  
      // Iterate through old segments and remove them from the segments list.
      for (Segment oldSegment : segments) {
        if (!this.segments.containsKey(oldSegment.index())) {
          throw new IllegalArgumentException("unknown segment at index: " + oldSegment.index());
        }
        this.segments.remove(oldSegment.index());
      }
  
      // Put the new segment in the segments list.
      this.segments.put(segment.index(), segment);
  
      resetCurrentSegment();
    }
docs: Inserts a segment.
  
  @param segment The segment to insert.
  @throws IllegalStateException if the segment is unknown