public boolean equals(Object o) { if (!(o instanceof IGraph)) { return false; } IGraph<Node> that = (IGraph) o; // Note: Order of checks is important for speed. // check if they have the same sets of nodes. Set<Node> thisNodes = this.getNodes(); Set<Node> thatNodes = that.getNodes(); if (!thisNodes.equals(thatNodes)) { return false; } // check if they have the same sets of edges. for (Node v : thisNodes) { Set<Node> thisPreds = this.getPreds(v); Set<Node> thatPreds = that.getPreds(v); if (!thisPreds.equals(thatPreds)) { return false; } } // check if they have the same sets of roots. Set<Node> thisRoots = this.getRoots(); Set<Node> thatRoots = that.getRoots(); if (!thisRoots.equals(thatRoots)) { return false; } return true; }