/**
  * Find the next result triple and bind the result vars appropriately.
  *
  * @param interpreter the calling interpreter whose trail should be used
  * @return FAIL if there are no more matches and the generator is closed, SUSPEND if there are no
  *     more matches but the generator could generate more, SATISFIED if a match has been found.
  */
 public synchronized StateFlag nextMatch(LPInterpreter interpreter) {
   while (resultIndex < generator.results.size()) {
     Triple result = (Triple) generator.results.get(resultIndex++);
     // Check if we have finished with this generator
     if (resultIndex >= generator.results.size() && generator.isComplete()) {
       generator.removeConsumer(this);
     }
     if (bindResult(result, interpreter)) {
       return StateFlag.SATISFIED;
     }
   }
   if (generator.isComplete()) {
     setFinished();
     generator.removeConsumer(this);
     return StateFlag.FAIL;
   } else {
     return StateFlag.SUSPEND;
   }
 }