peersim.graph
Class UndirectedGraph

java.lang.Object
  extended by peersim.graph.UndirectedGraph
All Implemented Interfaces:
Graph

public class UndirectedGraph
extends java.lang.Object
implements Graph

This class is an adaptor making any Graph an undirected graph by making its edges bidirectional. The graph to be made undirected is passed to the constructor. Only the reference is stored so if the directed graph changes later, the undirected version will follow that change. However, getNeighbours(int) has O(n) time complexity (in other words, too slow for large graphs).

See Also:
ConstUndirGraph

Constructor Summary
UndirectedGraph(Graph g)
           
 
Method Summary
 boolean clearEdge(int i, int j)
          not supported
 int degree(int i)
          Returns the degree of the given node.
 boolean directed()
          Returns true if the graph is directed otherwise false.
 java.lang.Object getEdge(int i, int j)
          If there is an (i,j) edge, returns that, otherwise if there is a (j,i) edge, returns that, otherwise returns null.
 java.util.Collection<java.lang.Integer> getNeighbours(int i)
          Uses sets as collection so does not support multiple edges now, even if the underlying directed graph does.
 java.lang.Object getNode(int i)
          Returns the node object associated with the index.
 boolean isEdge(int i, int j)
          Returns true if there is a directed edge between node i and node j.
 boolean setEdge(int i, int j)
          not supported
 int size()
          The number of nodes in the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UndirectedGraph

public UndirectedGraph(Graph g)
Method Detail

isEdge

public boolean isEdge(int i,
                      int j)
Description copied from interface: Graph
Returns true if there is a directed edge between node i and node j.

Specified by:
isEdge in interface Graph

getNeighbours

public java.util.Collection<java.lang.Integer> getNeighbours(int i)
Uses sets as collection so does not support multiple edges now, even if the underlying directed graph does.

Specified by:
getNeighbours in interface Graph

getNode

public java.lang.Object getNode(int i)
Description copied from interface: Graph
Returns the node object associated with the index. Optional operation.

Specified by:
getNode in interface Graph

getEdge

public java.lang.Object getEdge(int i,
                                int j)
If there is an (i,j) edge, returns that, otherwise if there is a (j,i) edge, returns that, otherwise returns null.

Specified by:
getEdge in interface Graph

size

public int size()
Description copied from interface: Graph
The number of nodes in the graph.

Specified by:
size in interface Graph

directed

public boolean directed()
Description copied from interface: Graph
Returns true if the graph is directed otherwise false.

Specified by:
directed in interface Graph

setEdge

public boolean setEdge(int i,
                       int j)
not supported

Specified by:
setEdge in interface Graph

clearEdge

public boolean clearEdge(int i,
                         int j)
not supported

Specified by:
clearEdge in interface Graph

degree

public int degree(int i)
Description copied from interface: Graph
Returns the degree of the given node. If the graph is directed, returns out degree.

Specified by:
degree in interface Graph