I want to write a function that tests if a undirected Graph is a tree.
So far, I'm using this:
Function<Graph<Integer>, Double> targetFunction = g -> {
boolean isConnected = Graphs.reachableNodes(g, g.nodes().iterator().next()).equals(g.nodes());
return isConnected && Graphs.hasCycle(g);
};
Is there already an implementation for this method in Guava (didn't find one) and if no, can this be improved?