// Textbook fragment 13.04 /** Setup method that is called prior to the DFS execution. */ protected void setup() {} /** Initializes result (called first, once per vertex visited). */ protected void initResult() {} /** Called when we encounter a vertex (v). */ protected void startVisit(Vertex v) {} /** Called after we finish the visit for a vertex (v). */ protected void finishVisit(Vertex v) {} /** Called when we traverse a discovery edge (e) from a vertex (from). */ protected void traverseDiscovery(Edge e, Vertex from) {} /** Called when we traverse a back edge (e) from a vertex (from). */ protected void traverseBack(Edge e, Vertex from) {} /** Determines whether the traversal is done early. */ protected boolean isDone() { return false; /* default value */ } /** Returns a result of a visit (if needed). */ protected R result() { return null; /* default value */ } /** Returns the final result of the DFS execute method. */ protected R finalResult(R r) { return r; /* default value */ }