package MaxFlowApplet.graph; import java.util.Vector; public class Vertex { // returns the number of outgoing edges public int fanOut() { return edgeOut.size(); }; // returns the number of incoming edges public int fanIn() { return edgeIn.size(); }; // returns the index-th outgoing edge (from 0) public Edge getEdgeOut(int index) { return (Edge) edgeOut.elementAt(index); }; // returns the index-th incoming edge (from 0) public Edge getEdgeIn(int index) { return (Edge) edgeIn.elementAt(index); }; // true iff there is an edge to vertex v public boolean isNeighbour(Vertex v) { return getEdgeTo(v)!=null; }; // returns the edge to vertex v public Edge getEdgeTo(Vertex v) { Edge e; int n = fanOut(); for(int i = 0; i < n; i++) { e = getEdgeOut(i); if (e.getVertexTo() == v) return e; }; return null; }; // adds an incoming edge public void addEdgeIn(Edge e) { edgeIn.addElement(e); }; // adds an outgoing edge public void addEdgeOut(Edge e) { edgeOut.addElement(e); }; // removes an outgoing edge public void removeEdgeOut(Edge e) { edgeOut.removeElement(e); }; // removes an incoming edge public void removeEdgeIn(Edge e) { edgeIn.removeElement(e); }; // vector of incoming edges protected Vector edgeIn = new Vector(INITIALSIZE, CAPINCREMENT); // vector of outgoing edges protected Vector edgeOut = new Vector(INITIALSIZE, CAPINCREMENT); // constants needed for the constructor of java.util.Vector protected static final int INITIALSIZE = 10; protected static final int CAPINCREMENT = 10; };