Search this API

y.base
Class Edge

java.lang.Object
  extended by y.base.Edge

public class Edge
extends java.lang.Object

Represents an edge, i.e., a directed connection between two nodes (represented by instances of class Node) in the directed graph data type Graph.
The directed stems from the fact that an edge has a distinct source node and a distinct target node. Using pair notation, an edge would be written as (<source node>, <target node>).

Most notably, an edge provides access to its source node (source()) and its target node (target()). Note that an edge can have the same node as its source and target. Such an edge is then called "self-loop" and method isSelfLoop() yields true.

Important: Class Graph is the single authority for any structural changes to the graph data type. Specifically, this means that there is no way to create or delete a node or an edge without using an actual Graph instance.

 

Constructor Summary
protected Edge(Graph g, Node v, Edge e1, Node w, Edge e2, int d1, int d2)
          Creates a new edge that belongs to the given graph.
 
Method Summary
 Edge createCopy(Graph g, Node v, Node w)
          Creates a copy of this edge that will be inserted into the given graph connecting the given source and target nodes.
 Graph getGraph()
          Returns the graph this edge belongs to.
 int index()
          Returns the index of this edge within its graph G.
 boolean isSelfLoop()
          Returns true if and only if this edge is a self-loop.
 Edge nextInEdge()
          Returns the successor of this edge in the list of incoming edges at its target node.
 Edge nextOutEdge()
          Returns the successor of this edge in the list of outgoing edges at its source node.
protected  void onReinsert()
          Callback method that is invoked from a graph just before this edge will be reinserted into that graph.
 Node opposite(Node v)
          Returns the node at the opposite edge end with respect to the given node.
 Edge prevInEdge()
          Returns the predecessor of this edge in the list of incoming edges at its target node.
 Edge prevOutEdge()
          Returns the predecessor of this edge in the list of outgoing edges at its source node.
 Node source()
          Returns the source node connected to this edge.
 Node target()
          Returns the target node connected to this edge.
 java.lang.String toString()
          Returns a String representation of this edge.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Edge

protected Edge(Graph g,
               Node v,
               Edge e1,
               Node w,
               Edge e2,
               int d1,
               int d2)
Creates a new edge that belongs to the given graph. The new edge e has source node v and target node w.

Edge e is inserted in such a way that an iteration over the edges at node v returns e and an iteration over the edges at w returns e

Precondition:
Edge e1 must have source node v and edge e2 must have target node w.
Parameters:
v - The source node of the edge.
e1 - An edge with source node v.
w - The target node of the edge.
e2 - An edge with target node w.
d1 - One of the object insertion specifiers Graph.BEFORE or Graph.AFTER.
d2 - One of the object insertion specifiers Graph.BEFORE or Graph.AFTER.
Method Detail

createCopy

public Edge createCopy(Graph g,
                       Node v,
                       Node w)
Creates a copy of this edge that will be inserted into the given graph connecting the given source and target nodes.

Parameters:
g - The graph the created edge will belong to.
v - The source node of the created edge.
w - The target node of the created edge.
Returns:
The newly created Edge object.

getGraph

public Graph getGraph()
Returns the graph this edge belongs to. If the edge does not belong to a graph, because it was removed or hidden from it, this method returns null.


index

public int index()
Returns the index of this edge within its graph G. Edge indices represent the ordering of standard edge iteration on G. The value of an index is >= 0 and < G.edgeCount().

Note that indices are subject to change whenever the sequence of edges in a graph is modified by either removing, hiding, reinserting, or unhiding an edge, or by explicitly changing its position in the sequence.

Precondition:
This edge must belong to some graph.
See Also:
Graph.removeEdge(Edge), Graph.hide(Edge), Graph.reInsertEdge(Edge), Graph.unhide(Edge), Graph.moveToFirst(Edge), Graph.moveToLast(Edge)

source

public Node source()
Returns the source node connected to this edge.

See Also:
target()

target

public Node target()
Returns the target node connected to this edge.

See Also:
source()

opposite

public Node opposite(Node v)
Returns the node at the opposite edge end with respect to the given node.

Note that self-loops have the same node at both edge ends.

Precondition:
The given node must be either the edge's source node or target node.

isSelfLoop

public boolean isSelfLoop()
Returns true if and only if this edge is a self-loop. An edge is called a self-loop, if it is adjacent to only one node, i.e., source node and target node are the same.


toString

public java.lang.String toString()
Returns a String representation of this edge.

Overrides:
toString in class java.lang.Object

onReinsert

protected void onReinsert()
Callback method that is invoked from a graph just before this edge will be reinserted into that graph.


nextOutEdge

public Edge nextOutEdge()
Returns the successor of this edge in the list of outgoing edges at its source node. If this edge is the last outgoing edge at its source node, then null is returned.

Precondition:
This edge must belong to some graph.
See Also:
prevOutEdge(), nextInEdge()

nextInEdge

public Edge nextInEdge()
Returns the successor of this edge in the list of incoming edges at its target node. If this edge is the last incoming edge at its target node, then null is returned.

Precondition:
This edge must belong to some graph.
See Also:
prevInEdge(), nextOutEdge()

prevOutEdge

public Edge prevOutEdge()
Returns the predecessor of this edge in the list of outgoing edges at its source node. If this edge is the first outgoing edge at its source node, then null is returned.

Precondition:
This edge must belong to some graph.
See Also:
nextOutEdge(), prevInEdge()

prevInEdge

public Edge prevInEdge()
Returns the predecessor of this edge in the list of incoming edges at its target node. If this edge is the first incoming edge at its target node, then null is returned.

Precondition:
This edge must belong to some graph.
See Also:
nextInEdge(), prevOutEdge()

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.