public class Graph extends Object
Constructor and Description |
---|
Graph()
Constructs the graph.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(Visitor aVisitor)
Implements a visitor design pattern.
|
void |
addEdge(Edge aEdge)
Adds an edge.
|
void |
addEdges(List<Edge> aEdges)
Adds a number of edges.
|
void |
addNode(Node aNode)
Adds a node.
|
void |
addNodes(List<Node> aNodes)
Adds a list of nodes.
|
void |
applyFilter(EdgeFilter aFilter)
Applies a filter to the graph for removing elements.
|
void |
extend(EdgeFactory aFactory)
Extends the graph with edges using an edge factory.
|
List<Edge> |
findIncoming(Node aNode)
Finds all incoming edges of a node.
|
Node |
findNode(String aName)
Finds a node with the given name.
|
List<Edge> |
findOutgoing(Node aNode)
Finds all outgoing edges of a node.
|
List<Edge> |
getEdges()
Gets the edges.
|
List<Node> |
getNodes()
Gets the nodes.
|
boolean |
removeEdge(Edge aEdge)
Removes an edge.
|
boolean |
removeNode(Node aNode)
Removes a node.
|
public void addNode(Node aNode)
aNode
- Node to add.IllegalArgumentException
- In case the node already exists. Node equality is checked
using equals
.public Node findNode(String aName)
aName
- Node name.public boolean removeNode(Node aNode)
aNode
- Node to remove.IllegalArgumentException
- In case there are edges of which the node is a part.public void addNodes(List<Node> aNodes)
aNodes
- Nodes to add.addNode(Node)
public void addEdge(Edge aEdge)
aEdge
- Edge to add.IllegalArgumentException
- In case one of the nodes of the edges is not part of the
graph or if the same edge (as determined by
Object.equals(Object)
is already a part of the graph.public boolean removeEdge(Edge aEdge)
aEdge
- Edge to remove.public void addEdges(List<Edge> aEdges)
aEdges
- Edges to add.public List<Node> getNodes()
public List<Edge> getEdges()
public void extend(EdgeFactory aFactory)
aFactory
- Edge factory.public void applyFilter(EdgeFilter aFilter)
aFilter
- Filter to apply.public List<Edge> findOutgoing(Node aNode)
e
for which e.getFrom().getName() =
aNode.getName()
.aNode
- Node for which to find outgoing edges.public List<Edge> findIncoming(Node aNode)
e
for which e.getTo().getName() =
aNode.getName()
.aNode
- Node for which to find incoming edges.public void accept(Visitor aVisitor)
aVisitor
- Visitor.Copyright © 2022. All rights reserved.