jcreek.util.graph
Class Graph

java.lang.Object
  extended byjcreek.util.graph.Graph
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ConceptMapModel

public class Graph
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
protected  java.util.ArrayList changeListeners
           
protected  java.util.ArrayList edgeList
           
protected  java.util.ArrayList nodeList
           
 
Constructor Summary
Graph()
          Creates a new, empty graph.
 
Method Summary
 void addEdge(Edge edge)
          Adds an edge to the graph.
 void addGraphChangeListener(GraphChangeListener listener)
          Adds a change listener to this model.
 void addNode(Node node)
          Adds the node to the graph.
 java.lang.Object clone()
          Returns an exact copy of this graph.
 boolean contains(Edge edge)
          Returns true if the edge suppleid is present in this graph.
 boolean contains(Node node)
          Returns true if the node supplied is present in this graph.
 int edgeSize()
          The number of edges in this graph.
 java.util.Iterator getEdgeIterator()
          Gives an iterator for all the edges in the graph.
 java.util.Iterator getEdgeIterator(Node node)
          Gives an iterator for the edges from a specific node in the graph.
 Edge[] getEdges()
          Returns an array of the edges of the graph.
 java.util.Iterator getNodeIterator()
          Gives an iterator for the nodes in this graph.
 Node[] getNodes()
          Returns a an array of the nodes of the graph.
 int nodeSize()
          The number of nodes in this graph.
 void removeEdge(Edge edge)
          Remove an edge from the graph.
 void removeGraphChangeListener(GraphChangeListener listener)
          Remove a change listener from the listener list.
 void removeNode(Node node)
          Remove a node from the graph.
 java.lang.String toString()
          Creates a string representation of the graph.
protected  void triggerEdgeAddedEvent(Edge edge)
           
protected  void triggerEdgeChangeEvent(GraphChangeEvent e)
           
protected  void triggerEdgeRemovedEvent(Edge edge)
           
protected  void triggerNodeAddedEvent(Node n)
           
protected  void triggerNodeChangeEvent(GraphChangeEvent e)
           
protected  void triggerNodeRemovedEvent(Node n)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodeList

protected java.util.ArrayList nodeList

edgeList

protected java.util.ArrayList edgeList

changeListeners

protected transient java.util.ArrayList changeListeners
Constructor Detail

Graph

public Graph()
Creates a new, empty graph.

Method Detail

addNode

public void addNode(Node node)
Adds the node to the graph.

Parameters:
node - The node to add.

addEdge

public void addEdge(Edge edge)
Adds an edge to the graph.

Parameters:
edge - The edge to add.

removeNode

public void removeNode(Node node)
Remove a node from the graph. This will also remove all edges to and from the node through a call to removeEdge().

Parameters:
node - The node to remove.

removeEdge

public void removeEdge(Edge edge)
Remove an edge from the graph.

Parameters:
edge - The edge to remove.

edgeSize

public int edgeSize()
The number of edges in this graph.

Returns:
The number of edges.

nodeSize

public int nodeSize()
The number of nodes in this graph.

Returns:
The number of nodes.

getNodeIterator

public java.util.Iterator getNodeIterator()
Gives an iterator for the nodes in this graph. (access through iterator may not be thread-safe?)


getNodes

public Node[] getNodes()
Returns a an array of the nodes of the graph.


getEdges

public Edge[] getEdges()
Returns an array of the edges of the graph.


getEdgeIterator

public java.util.Iterator getEdgeIterator(Node node)
Gives an iterator for the edges from a specific node in the graph. (access through iterator may not be thread-safe?)


getEdgeIterator

public java.util.Iterator getEdgeIterator()
Gives an iterator for all the edges in the graph. (access through iterator may not be thread-safe?)


contains

public boolean contains(Node node)
Returns true if the node supplied is present in this graph.


contains

public boolean contains(Edge edge)
Returns true if the edge suppleid is present in this graph.


addGraphChangeListener

public void addGraphChangeListener(GraphChangeListener listener)
Adds a change listener to this model. Any time a entity or edge is added, removed or changed in any way via the graph, or the set of selected entities are changed, this listener is notified.

Parameters:
listener - new listener to add notification list
See Also:
#removeChangeListener

removeGraphChangeListener

public void removeGraphChangeListener(GraphChangeListener listener)
Remove a change listener from the listener list.

Parameters:
listener - listener to remove from notification list
See Also:
#addChangeListener

triggerNodeRemovedEvent

protected void triggerNodeRemovedEvent(Node n)

triggerNodeAddedEvent

protected void triggerNodeAddedEvent(Node n)

triggerEdgeRemovedEvent

protected void triggerEdgeRemovedEvent(Edge edge)

triggerEdgeAddedEvent

protected void triggerEdgeAddedEvent(Edge edge)

triggerEdgeChangeEvent

protected void triggerEdgeChangeEvent(GraphChangeEvent e)

triggerNodeChangeEvent

protected void triggerNodeChangeEvent(GraphChangeEvent e)

clone

public java.lang.Object clone()
Returns an exact copy of this graph. This will also copy the node and edge objects in the graph maintaing the structure while making the copies independent of eachother.


toString

public java.lang.String toString()
Creates a string representation of the graph.



Created at IDI, NTNU by the Artificial Intelligence and Learning group