public class MapGraph extends Object implements Graph
Modifier and Type | Class and Description |
---|---|
protected class |
MapGraph.BottomUpIterator
An inner iterator class that traverses through the Graph bottom up.
|
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.
|
MapGraph(boolean preserveInsertionOrder)
The overloaded constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(GraphNode parent,
GraphNode child)
Adds an edge between two already existing nodes in the graph.
|
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.
|
Iterator |
bottomUpIterator()
Returns an iterator that traverses the graph bottom up from the leaves.
|
Object |
clone()
Returns a copy of the object.
|
Object |
get(Object key)
It returns the value associated with the key in the map.
|
List<GraphNode> |
getLeaves()
Returns the leaf nodes of the Graph.
|
GraphNode |
getNode(String identifier)
Returns the node matching the id passed.
|
List<GraphNode> |
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.
|
void |
resetEdges()
Resets all the dependencies in the Graph, while preserving the nodes.
|
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 MapGraph()
public MapGraph(boolean preserveInsertionOrder)
preserveInsertionOrder
- a boolean indicating whether you want to
preserve insertion order. If set to true, the
nodeIterator() will return nodes in the order
they were added.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 void resetEdges()
resetEdges
in interface Graph
public boolean remove(String identifier)
public void addEdge(String parent, String child)
public void addEdge(GraphNode parent, GraphNode child)
public void addEdges(String child, List parents)
public int size()
public Iterator nodeIterator()
nodeIterator
in interface Graph
public Iterator iterator()
public Iterator bottomUpIterator()
bottomUpIterator
in interface Graph
public Iterator<GraphNode> topologicalSortIterator()
topologicalSortIterator
in interface Graph
public String toString()
public boolean isEmpty()
public Object clone()