/** * {@inheritDoc} * * <p> * The complexity of adding a new edge in the graph depends on the number of edges incident to * the "affected region", and should in general be faster than recomputing the whole topological * ordering from scratch. * * @throws IllegalArgumentException if the edge would induce a cycle in the graph */ @Override public E addEdge(V sourceVertex, V targetVertex) { assertVertexExist(sourceVertex); assertVertexExist(targetVertex); E result; try { updateDag(sourceVertex, targetVertex); result = super.addEdge(sourceVertex, targetVertex); } catch (CycleFoundException e) { throw new IllegalArgumentException(EDGE_WOULD_INDUCE_A_CYCLE); } return result; }
/** * {@inheritDoc} * * <p> * The complexity of adding a new edge in the graph depends on the number of edges incident to * the "affected region", and should in general be faster than recomputing the whole topological * ordering from scratch. * * @throws IllegalArgumentException if the edge would induce a cycle in the graph */ @Override public boolean addEdge(V sourceVertex, V targetVertex, E e) { if (e == null) { throw new NullPointerException(); } else if (containsEdge(e)) { return false; } assertVertexExist(sourceVertex); assertVertexExist(targetVertex); boolean result; try { updateDag(sourceVertex, targetVertex); result = super.addEdge(sourceVertex, targetVertex, e); } catch (CycleFoundException ex) { throw new IllegalArgumentException(EDGE_WOULD_INDUCE_A_CYCLE); } return result; }