public class MapGraph extends Object implements Graph
Modifier and Type | Class and Description |
---|---|
protected class |
MapGraph.MapGraphIterator
An inner iterator class that traverses through the Graph.
|
Modifier and Type | Field and Description |
---|---|
private LogManager |
mLogger
The handle to the logging manager.
|
protected Map |
mStore
The map indexed by the id of the
GraphNode , used for storing
the nodes of the Graph. |
Constructor and Description |
---|
MapGraph()
The default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(String parent,
String child)
Adds an edge between two already existing nodes in the graph.
|
void |
addEdges(String child,
List parents)
A convenience method that allows for bulk addition of edges between
already existing nodes in the graph.
|
void |
addNode(GraphNode node)
Adds a node to the Graph.
|
void |
addRoot(GraphNode root)
Adds a single root node to the Graph.
|
Object |
clone()
Returns a copy of the object.
|
Object |
get(Object key)
It returns the value associated with the key in the map.
|
List |
getLeaves()
Returns the leaf nodes of the Graph.
|
GraphNode |
getNode(String identifier)
Returns the node matching the id passed.
|
List |
getRoots()
Returns the root nodes of the Graph.
|
boolean |
isEmpty()
Returns a boolean if there are no nodes in the graph.
|
Iterator |
iterator()
Returns an iterator that traverses through the graph using a graph
traversal algorithm.
|
Iterator |
nodeIterator()
Returns an iterator for the nodes in the Graph.
|
boolean |
remove(String identifier)
Removes a node from the Graph.
|
int |
size()
Returns the number of nodes in the graph.
|
Iterator<GraphNode> |
topologicalSortIterator()
Returns an iterator for the graph that traverses in topological sort
order.
|
String |
toString()
The textual representation of the graph node.
|
protected Map mStore
GraphNode
, used for storing
the nodes of the Graph. The value for each key is the corresponding
GraphNode
of the class.private LogManager mLogger
public void addNode(GraphNode node)
public void addRoot(GraphNode root)
addRoot
in interface Graph
root
- the GraphNode
to be added as a root.RuntimeException
- if a node with the same id already exists.public boolean remove(String identifier)
public List getRoots()
public List getLeaves()
public void addEdge(String parent, String child)
public void addEdges(String child, List parents)
public int size()
public Iterator nodeIterator()
nodeIterator
in interface Graph
public Iterator iterator()
public Iterator<GraphNode> topologicalSortIterator()
topologicalSortIterator
in interface Graph
public String toString()
public boolean isEmpty()
public Object clone()
Copyright © 2011 The University of Southern California. All Rights Reserved.