public E getEdge(Vertex oppositNode) { for (E e : edges()) { if (e.getOpposit((N) this) == oppositNode) { return e; } } return null; }
public void removeEdge(E e) { if ( getVertex(e.getSource().getIndex()) == e.getSource() && getVertex(e.getTarget().getIndex()) == e.getTarget()) { e.getSource().removeEdge(e); e.getTarget().removeEdge(e); } else { throw new RuntimeException("Edge connects Vertices that are not contained in this graph!"); } }
public boolean equals(Object o) { if (o == null) return false; if (o instanceof Edge) { //if both edges are of type 'undirected', it doesn't matter what is source and what target if (this.getType().equals(EdgeType.UNDIRECTED) && ((Edge) o).getType().equals(EdgeType.UNDIRECTED)) { return ((Edge) o).getSource().equals(source) && ((Edge) o).getTarget().equals(target) || ((Edge) o).getSource().equals(target) && ((Edge) o).getTarget().equals(source); } else { return ((Edge) o).getSource().equals(source) && ((Edge) o).getTarget().equals(target); } } return false; }
public void removeEdge(E e) { removeEdge(e.getSource(), e.getTarget(), e.getType()); }
/** * clears edge lists. nothing done here */ public void clear() { for (E e : edges()) { e.getOpposit((N) this).removeEdge(e); } adjList.clear(); }
public Iterable<TreeNode> edgeNodes(EdgeType type) { if (edges == null) { return new EmptyIterable<TreeNode>(); } return new EdgeNodeIterable<TreeNode, Edge<TreeNode>>(edges, this); }
protected E addEdge(N n1, N n2, EdgeFactory<? extends E, N> f) { E e = f.createEdge(n1, n2); return addEdge(e); }
public void removeVertex(N n) { removeVertex(n.getIndex()); }
public boolean isDirected() { return getType().isDirected(); }
/** * Removes vertex from the list. This checks if the list really contains the * given {@link IndexedElement}. If you are sure that the element is contained in * the list, directly call {@link #remove(int)} using teh index of the element and * avoid the contains check. * * @param v {@link IndexedElement} to remove * @return true if removal was successful */ public boolean remove(N v) { if (!contains(v)) return false; return remove(v.getIndex()) != null; }
/** * Return the parent of this node. * * @return parent the parent TreeNode or null */ public TreeNode getParent() { if (incompingEdge == null) return null; return incompingEdge.getSource(); }
@SuppressWarnings("unchecked") public DFS(Graph<N, E> g, N start) { this.g = g; colors = new Color[g != null ? g.getMaxIndex() : 0]; pis = (N[]) new Vertex[g != null ? g.getMaxIndex() : 0]; this.start = start; }
/** * Returns the maximal index over all nodes */ public int getMaxIndex() { return nodes.getMaximalIndex(); }
/** * Clear the list. This also set the index of each vertex back to -1. */ @SuppressWarnings("unchecked") public void clear() { for (N e : elements) { e.setIndex(-1); } position = 0; size = 0; elements = (N[]) new IndexedElement[loadFactor]; }