public class Graph extends Object implements Data, Cloneable, Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Graph.Type
Enumeration of the different types of implemented graphs.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_EDGE_LABEL_STRING
Default edge label used if the label is not relevant
|
static String |
DEFAULT_EDGE_NAME
Default Edge Name Prefix
|
static String |
DEFAULT_NODE_NAME
Default Node Name Prefix
|
Constructor and Description |
---|
Graph(String name)
Creates a new empty graph, i.e. the graph contains an empty node set and
an empty edge set.
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(String edgeName,
List<Node> incidentNodes)
Adds an unlabeled edge to this graph.
|
void |
addEdge(String edgeName,
String label,
List<Node> incidentNodes)
Adds a labeled edge to this graph.
|
void |
addNode(String nodeName)
Adds a new node with node name
nodeName and empty label to the graph. |
void |
addNode(String nodeName,
String label)
Adds a new node with node name
nodeName and label label
to the graph. |
Graph |
clone() |
boolean |
contains(Edge edge)
Returns
true if and only if this graph contains the edge edge . |
boolean |
contains(Node node)
Returns
true if and only if this graph contains the node node . |
boolean |
equals(Object o) |
Set<Node> |
getAdjacentNodes(Node node)
Returns the set of nodes incident to the node
node |
Set<Node> |
getAdjacentNodes(String nodeName)
Returns the set of nodes adjacent to the node
nodeName |
Edge |
getEdge(String edgeName)
Returns the edge with the name
edgeName or null if no
edge with the given name is existing. |
int |
getEdgeCount()
Returns the number of edges of this graph
|
Set<String> |
getEdgeNames()
Returns the set of edge names of this graph.
|
Set<Edge> |
getEdges()
Returns the set of edges of this graph.
|
Set<Edge> |
getIncidentEdges(Node node)
Returns the set of edges incident to the node
node |
Set<Edge> |
getIncidentEdges(String nodeName)
Returns the set of edges incident to the node
nodeName |
Map<String,Integer> |
getLabels()
Returns the map of labels of this graph.
|
String |
getName()
Returns the name of the graph.
|
Node |
getNode(String nodeName)
Returns the node with the name
nodeName or null if no
node with the given name is existing. |
int |
getNodeCount()
Returns the number of nodes of this graph
|
Set<String> |
getNodeNames()
Returns the set of node names of this graph.
|
Set<Node> |
getNodes()
Returns the set of nodes of this graph.
|
int |
getNumberOfAdjacentNodes(Node node)
Returns the number of nodes adjacent to the node
node |
int |
getNumberOfAdjacentNodes(String nodeName)
Returns the number of nodes adjacent to the node
node |
int |
getSize()
Returns the size of this graph, i.e. the number of nodes.
|
Graph.Type |
getType()
Returns the type of the data object.
|
boolean |
hasEdge(String edgeName)
Returns
true if and only if this graph contains
an edge with the name edgeName . |
int |
hashCode() |
boolean |
hasLoops()
Returns
true if and only if this graph contains
a loop. |
boolean |
hasNode(String nodeName)
Returns
true if and only if this graph contains
a node with the name nodeName . |
boolean |
isAdjacentTo(Node firstNode,
Node secondNode)
Returns
true if and only if the node firstNode is
adjacent to the node secondNode |
boolean |
isEmpty()
Returns
true if and only if the graph is empty, i.e. it does neither contain any node
nor any edge. |
void |
removeEdge(Edge edge)
Removes the edge
edge from this graph. |
void |
removeEdge(String edgeName)
Removes the edge with the name
edgeName from this graph. |
void |
removeNode(Node node)
Removes the node
node from this graph. |
void |
removeNode(String nodeName)
Removes the node with the name
nodeName from this graph. |
void |
setName(String name)
Sets the name of this graph
|
String |
toString() |
public static final String DEFAULT_EDGE_NAME
public static final String DEFAULT_NODE_NAME
public static final String DEFAULT_EDGE_LABEL_STRING
public Graph(String name)
name
- the name of the graphGraph(String, Set, Set)
public String getName()
public void setName(String name)
name
- the name of the graphpublic boolean isEmpty()
true
if and only if the graph is empty, i.e. it does neither contain any node
nor any edge.true
if the graph is empty, false
otherwisepublic boolean contains(Node node)
true
if and only if this graph contains the node node
.node
- the node to be checkedtrue
if the node is contained, false
otherwiseNullPointerException
- thrown if node
is nullpublic boolean hasNode(String nodeName) throws NullPointerException
true
if and only if this graph contains
a node with the name nodeName
.nodeName
- the name of the nodetrue
if a node of the given name has
been found, false
otherwiseNullPointerException
- thrown if nodeName
is nullpublic boolean hasLoops()
true
if and only if this graph contains
a loop.true
if a loop has
been found, false
otherwisepublic void addNode(String nodeName, String label) throws NullPointerException, IllegalArgumentException
nodeName
and label label
to the graph.nodeName
- the name of the new nodelabel
- the label of the new nodeNullPointerException
- thrown if nodeName
is nullIllegalArgumentException
- thrown if nodeName
is empty or if
a node with name nodeName
is already existingpublic void addNode(String nodeName) throws NullPointerException, IllegalArgumentException
nodeName
and empty label to the graph.nodeName
- the name of the new nodeNullPointerException
- thrown if nodeName
is nullIllegalArgumentException
- thrown if nodeName
is empty or if
a node with name nodeName
is already existingpublic void removeNode(Node node) throws NullPointerException, IllegalArgumentException
node
from this graph.node
- the node to be removedNullPointerException
- thrown if node
is null
IllegalArgumentException
- if node
is not a node of this graphpublic void removeNode(String nodeName) throws NullPointerException, IllegalArgumentException
nodeName
from this graph.nodeName
- the name of the nodeNullPointerException
- thrown if nodeName
is null
IllegalArgumentException
- thrown if nodeName
is empty or the node is not existingpublic Node getNode(String nodeName) throws NullPointerException, IllegalArgumentException
nodeName
or null
if no
node with the given name is existing.nodeName
- the name of the nodenull
if no node has been foundNullPointerException
- thrown if nodeName
is null
IllegalArgumentException
- thrown if nodeName
is emptypublic Set<String> getNodeNames()
public Set<Node> getNodes()
public Map<String,Integer> getLabels()
public boolean contains(Edge edge)
true
if and only if this graph contains the edge edge
.edge
- the edge to be checkedtrue
if the edge is contained, false
otherwiseNullPointerException
- thrown if edge
is nullpublic boolean hasEdge(String edgeName)
true
if and only if this graph contains
an edge with the name edgeName
.edgeName
- the name of the edgetrue
if an edge of the given name has
been found, false
otherwisepublic void addEdge(String edgeName, String label, List<Node> incidentNodes) throws NullPointerException, IllegalArgumentException
edgeName
- the name of the new edgelabel
- the label of the new edgeincidentNodes
- the incident nodes of the new edgeNullPointerException
- if edgeName
, edgeLabel
or
incidentNodes
is nullIllegalArgumentException
- if edgeName
or edgeLabel
are empty, at least one node of incidentNodes
is not contained in
this graph or if an edge with name edgeName
is already existingpublic void addEdge(String edgeName, List<Node> incidentNodes)
edgeName
- the name of the new edgeincidentNodes
- the incident nodes of the new edgeNullPointerException
- if edgeName
or incidentNodes
is nullIllegalArgumentException
- if edgeName
is empty, at least one node of
incidentNodes
is not contained in this graph or if an edge with name
edgeName
is already existingpublic void removeEdge(Edge edge) throws NullPointerException, IllegalArgumentException
edge
from this graph.edge
- the edge to be removedNullPointerException
- thrown if edge
is null
IllegalArgumentException
- thrown if the edge
is not an edge of this graphpublic void removeEdge(String edgeName) throws NullPointerException, IllegalArgumentException
edgeName
from this graph.edgeName
- the name of the edgeNullPointerException
- thrown if edgeName
is null
IllegalArgumentException
- thrown if edgeName
is empty or the edge is not existingpublic Edge getEdge(String edgeName) throws NullPointerException, IllegalArgumentException
edgeName
or null
if no
edge with the given name is existing.edgeName
- the name of the edgenull
if no node has been foundNullPointerException
- thrown if nodeName
is null
IllegalArgumentException
- thrown if edgeName
is emptypublic Set<String> getEdgeNames()
public Set<Edge> getEdges()
public Set<Edge> getIncidentEdges(Node node)
node
node
- the nodepublic Set<Edge> getIncidentEdges(String nodeName)
nodeName
nodeName
- the name of the nodepublic Set<Node> getAdjacentNodes(Node node)
node
node
- the nodepublic Set<Node> getAdjacentNodes(String nodeName)
nodeName
nodeName
- the name of the nodepublic int getNumberOfAdjacentNodes(Node node)
node
node
- the nodepublic int getNumberOfAdjacentNodes(String nodeName)
node
nodeName
- the name of the nodepublic boolean isAdjacentTo(Node firstNode, Node secondNode)
true
if and only if the node firstNode
is
adjacent to the node secondNode
firstNode
- the first nodesecondNode
- the second nodetrue
if the first node is adjacent to the second node,
false
otherwisepublic int getSize()
public int getNodeCount()
public int getEdgeCount()
public Graph.Type getType()
Data