net.sourceforge.combean.samples.simplegraphs
Class NumberGraph

Package class diagram package NumberGraph
java.lang.Object
  extended by net.sourceforge.combean.samples.simplegraphs.NumberGraph
All Implemented Interfaces:
Graph, GlobalIndexedNodesGraphProp, GlobalNodesGraphProp, GlobalNumberedNodesGraphProp, NeighborhoodGraphProp, OutgoingEdgeNeighborhoodGraphProp
Direct Known Subclasses:
CompositeNumberGraph, SimpleNumberGraph

public abstract class NumberGraph
extends Object
implements Graph, OutgoingEdgeNeighborhoodGraphProp, GlobalNumberedNodesGraphProp

This class represents a graph where every node is identified by a long-value.


Field Summary
static int FIRSTNODE
          The number of the first node in the graph.
static int NOSUCHNODE
          The virtual node number if no such node exists.
 
Fields inherited from interface net.sourceforge.combean.interfaces.graph.prop.GlobalIndexedNodesGraphProp
UNDEFINED_NODE
 
Constructor Summary
NumberGraph()
           
 
Method Summary
protected abstract  int calcNextNode(int sourceNodeNum, int minNodeNum)
          Template method for calculating neighbors.
 boolean contains(NumberNode v)
          Check whether a given node is contained in the graph.
 NumberNode convertNumToNode(int num)
          Create a node in the graph.given its number
 boolean empty()
          Check if the graph is empty.
 NodeIterator getAllNodesIterator()
          Return an iterator for all nodes in the graph
 Class getEdgeClass()
           
 Node getFirstNode(Edge e)
          Return the first node of an edge.
 EdgeIterator getIncidentEdges(Node v)
          Return an iterator for the local neighborhood of v
 Node getNode(int index)
          Returns the node with the given index.
 Class getNodeClass()
           
 int getNodeNumber(Node v)
          Get the number of a given node.
 Node getOtherNode(Edge e, Node v)
          Given an edge and an incident node, return the other node of the edge
 EdgeIterator getOutgoingEdges(Node v)
          Get all outgoing edges of a given node
 Node getSecondNode(Edge e)
          Return the second node of an edge.
protected  int nextNode(NumberNode startNode, NumberNode currNode)
          Helps NumberNodeIterators to calculate the next node when iterating through neighbors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp
getNumNodes
 

Field Detail

FIRSTNODE

public static final int FIRSTNODE
The number of the first node in the graph.

See Also:
Constant Field Values

NOSUCHNODE

public static final int NOSUCHNODE
The virtual node number if no such node exists.

See Also:
Constant Field Values
Constructor Detail

NumberGraph

public NumberGraph()
Method Detail

getEdgeClass

public Class getEdgeClass()
Specified by:
getEdgeClass in interface Graph

getNodeClass

public Class getNodeClass()
Specified by:
getNodeClass in interface Graph

getAllNodesIterator

public NodeIterator getAllNodesIterator()
Description copied from interface: GlobalNodesGraphProp
Return an iterator for all nodes in the graph

Specified by:
getAllNodesIterator in interface GlobalNodesGraphProp
Returns:
iterator through all nodes
See Also:
GlobalNodesGraphProp.getAllNodesIterator()

getNode

public Node getNode(int index)
Description copied from interface: GlobalIndexedNodesGraphProp
Returns the node with the given index.

Specified by:
getNode in interface GlobalIndexedNodesGraphProp
Returns:
node with given index

getNodeNumber

public int getNodeNumber(Node v)
Description copied from interface: GlobalNumberedNodesGraphProp
Get the number of a given node.

Specified by:
getNodeNumber in interface GlobalNumberedNodesGraphProp
Parameters:
v - the node for which the number shall be returned.
Returns:
the number of the node in the interval [0 ... number of nodes-1]

convertNumToNode

public final NumberNode convertNumToNode(int num)
Create a node in the graph.given its number

Parameters:
num - the number of the node to be created
Returns:
the node with the given number or null if the node does not exist in the graph or num is NOSUCHNODE.

getIncidentEdges

public final EdgeIterator getIncidentEdges(Node v)
Description copied from interface: NeighborhoodGraphProp
Return an iterator for the local neighborhood of v

Specified by:
getIncidentEdges in interface NeighborhoodGraphProp
Parameters:
v - the node for which the neighborhood shall be given.
Returns:
an iterator through the neighborhood

getOutgoingEdges

public EdgeIterator getOutgoingEdges(Node v)
Description copied from interface: OutgoingEdgeNeighborhoodGraphProp
Get all outgoing edges of a given node

Specified by:
getOutgoingEdges in interface OutgoingEdgeNeighborhoodGraphProp
Returns:
the incoming edges of v

getFirstNode

public final Node getFirstNode(Edge e)
Description copied from interface: NeighborhoodGraphProp
Return the first node of an edge. For directed graphs this is the source of the edge. For undirected graphs the ordering of the nodes of an edge is arbitrary.

Specified by:
getFirstNode in interface NeighborhoodGraphProp
Parameters:
e - the edge
Returns:
the first node of the given edge

getSecondNode

public final Node getSecondNode(Edge e)
Description copied from interface: NeighborhoodGraphProp
Return the second node of an edge. For directed graphs this is the target of the edge. For undirected graphs the ordering of the nodes of an edge is arbitrary.

Specified by:
getSecondNode in interface NeighborhoodGraphProp
Parameters:
e - the edge
Returns:
the second node of the given edge

getOtherNode

public final Node getOtherNode(Edge e,
                               Node v)
Description copied from interface: NeighborhoodGraphProp
Given an edge and an incident node, return the other node of the edge

Specified by:
getOtherNode in interface NeighborhoodGraphProp
Parameters:
e - the given edge
v - the give node
Returns:
the other incident node of e

nextNode

protected int nextNode(NumberNode startNode,
                       NumberNode currNode)
Helps NumberNodeIterators to calculate the next node when iterating through neighbors.

Parameters:
startNode - the start node of the NumberNeighborIterator
currNode - the current node of the NumberNeighborIterator or null is this is the first iteration
Returns:
the next node of the NumberNeighborIterator or NOSUCHNODE if no next node exists

calcNextNode

protected abstract int calcNextNode(int sourceNodeNum,
                                    int minNodeNum)
Template method for calculating neighbors. Calculates the smallest number >= minNodeNum of a node in the neighborhood of the node with the number sourceNumNode or NOSUCHNODE if no next node exists. It is guaranteed that the graph in non-empty and that the node number startNodeNum is contained in the graph. Note that minNodeNum may also be negative.

Parameters:
sourceNodeNum -
minNodeNum -
Returns:
the next node in the neighborhood of the given node
See Also:
nextNode(NumberNode, NumberNode)

contains

public final boolean contains(NumberNode v)
Check whether a given node is contained in the graph.

Parameters:
v - the node to be checked
Returns:
true if v is contained in the graph

empty

public final boolean empty()
Check if the graph is empty.

Returns:
true if the graph does not contain any node.