annas.graph
Class Graph<N,A extends ArcInterface<N>>

java.lang.Object
  extended by annas.graph.Graph<N,A>
Type Parameters:
N - Node type
A - Arc type
All Implemented Interfaces:
GraphInterface<N,A>
Direct Known Subclasses:
DirectedGraph, UndirectedGraph

public abstract class Graph<N,A extends ArcInterface<N>>
extends java.lang.Object
implements GraphInterface<N,A>

Base graph class

Author:
Sam Wilson

Constructor Summary
Graph()
          Default Constructor
Graph(GraphObserver observer)
          Constructor used to set the observer from creation
 
Method Summary
 boolean addArc(N tail, N head, WeightedInterface wi)
          Adds an arc to the graph
 boolean addNode(N node)
          Adds a node to the graph
 boolean contains(N node)
          Checks if the graph contains a node
 java.util.ArrayList<A> getArc(N tail)
          Gets all arcs which originate from the given node
 java.util.ArrayList<A> getArc(N tail, N head)
          Gets all arcs from the tail to the head
 ArcFactory<N,A> getArcFactory()
          Gets the @see ArcFactory used by the graph
 java.util.ArrayList<N> getNodeMap()
          Gets a list of nodes in the graph
 int getNuArcs()
          Number of arcs contained within the graph
 int getNuNodes()
          Number of nodes contained within the graph
 GraphObserver getObserver()
          Current GraphObserver
 int getVersion()
          Gets the version of the graph.
 boolean removeArc(N tail)
          Removes all arcs with originating from a node
 boolean removeArc(N tail, A arc)
          Removes an arc from the graph
 boolean removeArc(N tail, N head)
          Removes all arc from the graph
 boolean removeNode(N node)
          Removes a node from the graph
 void resetArcs()
          Removes all arcs from the graph
 void setObserver(GraphObserver observer)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph()
Default Constructor


Graph

public Graph(GraphObserver observer)
Constructor used to set the observer from creation

Parameters:
observer -
Method Detail

getObserver

public GraphObserver getObserver()
Description copied from interface: GraphInterface
Current GraphObserver

Specified by:
getObserver in interface GraphInterface<N,A extends ArcInterface<N>>
Returns:
GraphObserver

setObserver

public void setObserver(GraphObserver observer)

addArc

public boolean addArc(N tail,
                      N head,
                      WeightedInterface wi)
Description copied from interface: GraphInterface
Adds an arc to the graph

Specified by:
addArc in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
tail - Tail of the arc
head - Head of the arc
wi - WeightedInterface
Returns:
true if the arc is successfully added to the graph

addNode

public boolean addNode(N node)
Description copied from interface: GraphInterface
Adds a node to the graph

Specified by:
addNode in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
node - to add to the graph
Returns:

contains

public boolean contains(N node)
Description copied from interface: GraphInterface
Checks if the graph contains a node

Specified by:
contains in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
node - to check if it is contained within the graph
Returns:
true if the node is contained within the graph

getArc

public java.util.ArrayList<A> getArc(N tail)
Description copied from interface: GraphInterface
Gets all arcs which originate from the given node

Specified by:
getArc in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
tail - tail of the arcs
Returns:
An arraylist of all arcs originating from the given nodes

getArc

public java.util.ArrayList<A> getArc(N tail,
                                     N head)
Description copied from interface: GraphInterface
Gets all arcs from the tail to the head

Specified by:
getArc in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
tail - tail of the arc
head - head of the arc
Returns:
An arraylist of all arcs from the tail to the head

getArcFactory

public ArcFactory<N,A> getArcFactory()
Description copied from interface: GraphInterface
Gets the @see ArcFactory used by the graph

Specified by:
getArcFactory in interface GraphInterface<N,A extends ArcInterface<N>>
Returns:
ArcFactory used by the graph

getNodeMap

public java.util.ArrayList<N> getNodeMap()
Description copied from interface: GraphInterface
Gets a list of nodes in the graph

Specified by:
getNodeMap in interface GraphInterface<N,A extends ArcInterface<N>>
Returns:
list of nodes in the graph

removeArc

public boolean removeArc(N tail,
                         A arc)
Description copied from interface: GraphInterface
Removes an arc from the graph

Specified by:
removeArc in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
tail - tail of the arc to remove
arc - arc to remove
Returns:
true if the arc was successfully removed

removeArc

public boolean removeArc(N tail,
                         N head)
Description copied from interface: GraphInterface
Removes all arc from the graph

Specified by:
removeArc in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
tail - tail of the arc to remove
head - head of the arc to remove
Returns:

removeArc

public boolean removeArc(N tail)
Description copied from interface: GraphInterface
Removes all arcs with originating from a node

Specified by:
removeArc in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
tail - tail of the arc
Returns:
true if all arcs originating from the node were removed

resetArcs

public void resetArcs()
Description copied from interface: GraphInterface
Removes all arcs from the graph

Specified by:
resetArcs in interface GraphInterface<N,A extends ArcInterface<N>>

removeNode

public boolean removeNode(N node)
Description copied from interface: GraphInterface
Removes a node from the graph

Specified by:
removeNode in interface GraphInterface<N,A extends ArcInterface<N>>
Parameters:
node - to remove from the graph
Returns:
true if the node is successfully removed from the graph

getVersion

public int getVersion()
Description copied from interface: GraphInterface
Gets the version of the graph. The graph version is initially 0, each method invoked which modifies the graph increments the field by 1.

Specified by:
getVersion in interface GraphInterface<N,A extends ArcInterface<N>>
Returns:

getNuArcs

public int getNuArcs()
Description copied from interface: GraphInterface
Number of arcs contained within the graph

Specified by:
getNuArcs in interface GraphInterface<N,A extends ArcInterface<N>>
Returns:

getNuNodes

public int getNuNodes()
Description copied from interface: GraphInterface
Number of nodes contained within the graph

Specified by:
getNuNodes in interface GraphInterface<N,A extends ArcInterface<N>>
Returns: