@Override
 public void finishDoc() throws IOException {
   assert state == PostingsConsumerState.START;
   state = PostingsConsumerState.INITIAL;
   if (fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
     assert positionCount == 0; // we should not have fed any positions!
   } else {
     assert positionCount == freq;
   }
   in.finishDoc();
 }
 @Override
 public void startDoc(int docID, int freq) throws IOException {
   assert state == PostingsConsumerState.INITIAL;
   state = PostingsConsumerState.START;
   assert docID >= 0;
   if (fieldInfo.getIndexOptions() == IndexOptions.DOCS_ONLY) {
     assert freq == -1;
     this.freq = 0; // we don't expect any positions here
   } else {
     assert freq > 0;
     this.freq = freq;
     totalTermFreq += freq;
   }
   this.positionCount = 0;
   this.lastPosition = 0;
   this.lastStartOffset = 0;
   docFreq++;
   visitedDocs.set(docID);
   in.startDoc(docID, freq);
 }
 @Override
 public void addPosition(int position, BytesRef payload, int startOffset, int endOffset)
     throws IOException {
   assert state == PostingsConsumerState.START;
   assert positionCount < freq;
   positionCount++;
   assert position >= lastPosition
       || position == -1; /* we still allow -1 from old 3.x indexes */
   lastPosition = position;
   if (fieldInfo.getIndexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {
     assert startOffset >= 0;
     assert startOffset >= lastStartOffset;
     lastStartOffset = startOffset;
     assert endOffset >= startOffset;
   } else {
     assert startOffset == -1;
     assert endOffset == -1;
   }
   if (payload != null) {
     assert fieldInfo.hasPayloads();
   }
   in.addPosition(position, payload, startOffset, endOffset);
 }