class OntologyAlgorithm {

  public static boolean existsPath(
      Ontology ontology,
      final TermId sourceID,
      TermId destID) {
    // special case -- a term cannot have a path to itself in an ontology (DAG)
    if (sourceID.equals(destID)) return false;
    final DefaultDirectedGraph<TermId, IdLabeledEdge> graph = ontology.getGraph();
    List<TermId> visited = new ArrayList<>();
    BreadthFirstSearch<TermId, IdLabeledEdge> bfs = new BreadthFirstSearch<>();
    bfs.startFromForward(
        graph,
        sourceID,
        (g, termId) -> {
          visited.add(termId);
          return true;
        });
    return visited.contains(destID);
  }

  private  OntologyAlgorithm();

}