private Map.Entry<List<String>,Map<String,Document>> generateIndexDocuments(int ndocs,boolean requiresContexts){
  Map<String,Document> docs=new HashMap<>();
  List<String> invalidDocTerms=new ArrayList<>();
  for (int i=0; i < ndocs; i++) {
    Document doc=new Document();
    boolean invalidDoc=false;
    Field field=null;
    if (usually()) {
      field=new TextField(FIELD_NAME,"field_" + i,Field.Store.YES);
      doc.add(field);
    }
 else {
      invalidDoc=true;
    }
    if (usually()) {
      Field payload=new StoredField(PAYLOAD_FIELD_NAME,new BytesRef("payload_" + i));
      doc.add(payload);
    }
    if (requiresContexts || usually()) {
      if (usually()) {
        for (int j=0; j < atLeast(2); j++) {
          doc.add(new StoredField(CONTEXT_FIELD_NAME,new BytesRef("context_" + i + "_"+ j)));
        }
      }
    }
    if (usually()) {
      Field weight=(rarely()) ? new StoredField(WEIGHT_FIELD_NAME,100d + i) : new NumericDocValuesField(WEIGHT_FIELD_NAME,100 + i);
      doc.add(weight);
    }
    String term=null;
    if (invalidDoc) {
      term=(field != null) ? field.stringValue() : "invalid_" + i;
      invalidDocTerms.add(term);
    }
 else {
      term=field.stringValue();
    }
    docs.put(term,doc);
  }
  return new SimpleEntry<>(invalidDocTerms,docs);
}

private Map . Entry < List < String > , Map < String , Document > > generateIndexDocuments ( int ndocs , boolean requiresContexts ) { Map < String , Document > docs = new HashMap < > ( ) ; List < String > invalidDocTerms = new ArrayList < > ( ) ; for ( int i = 0 ; i < ndocs ; i ++ ) { Document doc = new Document ( ) ; boolean invalidDoc = false ; Field field = null ; if ( usually ( ) ) { field = new TextField ( FIELD_NAME , "field_" + i , Field . Store . YES ) ; doc . add ( field ) ; } else { invalidDoc = true ; } if ( usually ( ) ) { Field payload = new StoredField ( PAYLOAD_FIELD_NAME , new BytesRef ( "payload_" + i ) ) ; doc . add ( payload ) ; } if ( requiresContexts || usually ( ) ) { if ( usually ( ) ) { for ( int j = 0 ; j < atLeast ( 2 ) ; j ++ ) { doc . add ( new StoredField ( CONTEXT_FIELD_NAME , new BytesRef ( "context_" + i + "_" + j ) ) ) ; } } } if ( usually ( ) ) { Field weight = ( rarely ( ) ) ? new StoredField ( WEIGHT_FIELD_NAME , 100d + i ) : new NumericDocValuesField ( WEIGHT_FIELD_NAME , 100 + i ) ; doc . add ( weight ) ; } String term = null ; if ( invalidDoc ) { term = ( field != null ) ? field . stringValue ( ) : "invalid_" + i ; invalidDocTerms . add ( term ) ; } else { term = field . stringValue ( ) ; } docs . put ( term , doc ) ; } return new SimpleEntry < > ( invalidDocTerms , docs ) ; }
returns pair ( list of invalid document terms , map of document term - & gt ; document )
