class OntologyTerms {

  public static <O extends Ontology> void visitChildrenOf(
    TermId termId, O ontology, TermVisitor<O> termVisitor) {
    // Setup BFS for visiting the termds.
    BreadthFirstSearch<TermId, IdLabeledEdge> bfs = new BreadthFirstSearch<>();
    // TODO: Is there a more elegant solution to this problem?
    DefaultDirectedGraph<TermId, IdLabeledEdge> graph = ontology.getGraph();

    // Perform BFS.
    bfs.startFromReverse(
        graph,
        termId,
        new VertexVisitor<TermId, IdLabeledEdge>() {
          @Override
          public boolean visit(DefaultDirectedGraph<TermId, IdLabeledEdge> g, TermId v) {
            return termVisitor.visit(ontology, v);
          }
        });
  }

}