code: public List<T> sortTopologically(Set<T> payloads) {
      List<T> result = new ArrayList<>();
  
      Set<T> input = new HashSet<>(payloads);
      Deque<DirectedAcyclicGraphNode<T>> toVisit = new ArrayDeque<>(mRoots);
      while (!toVisit.isEmpty()) {
        DirectedAcyclicGraphNode<T> visit = toVisit.removeFirst();
        T payload = visit.getPayload();
        if (input.remove(payload)) {
          result.add(visit.getPayload());
        }
        toVisit.addAll(visit.getChildren());
      }
  
      Preconditions.checkState(input.isEmpty(), "Not all the given payloads are in the DAG: ",
          input);
      return result;
    }
docs: Sorts a given set of payloads topologically based on the DAG. This method requires all the
  payloads to be in the DAG.
  
  @param payloads the set of input payloads
  @return the payloads after topological sort