Graph Interface: Removals

There are two remove methods in the Graph interface; one to remove a vertex and another to remove an edge.

/**
 * Remove a vertex.
 *
 * @param v Vertex position to remove.
 * @return Element from removed vertex position.
 * @throws PositionException If vertex position is invalid.
 * @throws RemovalException  If vertex still has incident edges.
 */
V remove(Vertex<V> v) throws PositionException, RemovalException;
/**
 * Remove an edge.
 *
 * @param e Edge position to remove.
 * @return Element from removed edge position.
 * @throws PositionException If edge position is invalid.
 */
E remove(Edge<E> e) throws PositionException;

By convention, we return the data stored in a vertex or an edge when we remove it.

Note that you may not remove a vertex that still has incident edges.

In other words, before removing a vertex, you must remove the incoming and outgoing edges incident to it.

Aside: The remove method is overloaded. The Java compiler allows overloading base on subtypes. (The compiler does not consider return type when differentiating methods, it is not part of the method signature.) In fact, a motivation behind using Vertex and Edge interfaces as positions (instead of only Position), is that we can overload method names to keep down interface complexity. We also get some degree of static type safety: clients who confuse vertex and edge positions will notice at compile-time.