public interface Graph extends Attributable
A graph object belongs to a graph model, which really contains the data. Graph
objects are therefore only accessors, with all convinient methods to read and
modify the structure. Hence, multiple Graph objects can
exists.
GraphController graphController = Lookup.getDefault().lookup(GraphController.class); GraphModel model = graphController.getModel(); Graph graph = model.getGraph();Note: This shows how to get the complete graph, for getting only the currently visualized graph, call
model.getGraphVisible() instead.
There is two different way to perform read locking:
readLock() and readUnlock()NodeIterable
and EdgeIterablereadUnlockAll()
to release all the locks.
Note: Write locking is automatically done when modifying th graph (add, remove, ...).
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(Edge edge)
Add
edge to the graph. |
boolean |
addNode(Node node)
Add a node to the graph.
|
void |
clear()
Removes all nodes and edges in the graph.
|
void |
clearEdges()
Removes all edges in the graph.
|
void |
clearEdges(Node node)
Removes all edges incident to
node. |
boolean |
contains(Edge edge)
Returns true if the graph contains
edge. |
boolean |
contains(Node node)
Returns true if the graph contains
node. |
int |
getDegree(Node node)
Returns the degree of
node. |
Edge |
getEdge(int id)
Returns the edge with identifier equals to
id. |
Edge |
getEdge(Node node1,
Node node2)
Finds and returns a directed or undirected edge that connects
node1 and
node2. |
Edge |
getEdge(String id)
Returns the edge with identifier equals to
id. |
int |
getEdgeCount()
Returns the number of edges in the graph
|
EdgeIterable |
getEdges()
Returns edges contained in the graph.
|
EdgeIterable |
getEdges(Node node)
Returns edges incident to
node. |
int |
getEdgeVersion()
Return the current edge version of the graph.
|
GraphModel |
getGraphModel()
Returns the graph model this graph belongs to.
|
NodeIterable |
getNeighbors(Node node)
Returns neighbors of
node. |
Node |
getNode(int id)
Returns the node with identifier equals to
id. |
Node |
getNode(String id)
Returns the node with identifier equals to
id. |
int |
getNodeCount()
Returns the number of nodes in the graph.
|
NodeIterable |
getNodes()
Returns nodes contained in the graph.
|
int |
getNodeVersion()
Return the current node version of the graph.
|
Node |
getOpposite(Node node,
Edge edge)
Returns the adjacent node of
node through edge. |
GraphView |
getView()
Returns the graph view this graph belongs to.
|
boolean |
isAdjacent(Edge edge1,
Edge edge2)
Returns
true if edge1 is adjacent to edge2. |
boolean |
isAdjacent(Node node1,
Node node2)
Returns
true if node1 is adjacent to node2. |
boolean |
isDirected(Edge edge)
Returns
true if edge is a directed edge in the current graph. |
boolean |
isSelfLoop(Edge edge)
Returns
true if edge is a self-loop. |
void |
readLock()
Acquires a read lock on the graph.
|
void |
readUnlock()
Releases the read lock on the graph.
|
void |
readUnlockAll()
Safe method that releases all read locks the calling thread has acquired.
|
boolean |
removeEdge(Edge edge)
Remove
edge from the graph. |
boolean |
removeNode(Node node)
Remove
node from the graph. |
void |
setId(Edge edge,
String id)
Sets the string identifier of
edge. |
void |
setId(Node node,
String id)
Sets the string identifier of
node. |
void |
writeLock()
Acquires a write lock on the graph.
|
void |
writeUnlock()
Release the write lock on the graph.
|
getAttributesboolean addEdge(Edge edge)
edge to the graph. Graph does not accept parallel edges.
Fails if edge is already in the graph.edge - the edge to addIllegalArgumentException - if edge is null,
or if nodes are not legal nodes for this edge,
or if edge is directed when the graph is undirected,
or if edge is undirected when the graph is directed,IllegalMonitorStateException - if the current thread is holding a read lockboolean addNode(Node node)
node - the node to addIllegalArgumentException - if node is nullIllegalMonitorStateException - if the current thread is holding a read lockboolean removeEdge(Edge edge)
edge from the graph.
Fails if the edge doesn't exist.edge - the edge to removeIllegalArgumentException - if edge is null or nodes not legal in
the graphIllegalMonitorStateException - if the current thread is holding a read lockboolean removeNode(Node node)
node from the graph. All node's children and incident edges will
also be removed.node - the node to removeIllegalArgumentException - if node is null
or not legal in the graph.IllegalMonitorStateException - if the current thread is holding a read lockboolean contains(Node node)
node.
Warning: This method is not thread safe, be sure to call it in a locked statement.
node - the node whose presence is requirednodeIllegalArgumentException - if node is nullboolean contains(Edge edge)
edge.
Warning: This method is not thread safe, be sure to call it in a locked statement.
edge - the edge whose presence is requirededgeIllegalArgumentException - if edge is nullNode getNode(int id)
id. If not found,
returns null. This id is generated and can be found in
Node.getId().
Warning: This method is not thread safe, be sure to call it in a locked statement.
id - a positive numberid, or null if not foundNode getNode(String id)
id. If not found,
returns null. This id is set by user and can be found at
NodeData.getId(). To set this Id, use Graph.setId().
The node must be present in the view this graph is from.
Warning: This method is not thread safe, be sure to call it in a locked statement.
id - the string identifier, uniqueid, or null if not foundEdge getEdge(int id)
id. If not found,
returns null. This id is generated and can be found in
Edge.getId().
Warning: This method is not thread safe, be sure to call it in a locked statement.
id - a positive numberid, or null if not foundEdge getEdge(String id)
id. If not found,
returns null. This id is set by user and can be found at
EdgeData.getId(). To set this Id, use Graph.setId().
Warning: This method is not thread safe, be sure to call it in a locked statement.
id - the string identifier, uniqueid, or null if not foundEdge getEdge(Node node1, Node node2)
node1 and
node2. Returns null if no such edge is found.
Warning: This method is not thread safe, be sure to call it in a locked statement.
node1 - the first incident node of the queried edgenode2 - thge second incident node of the queried edgenode1 and node2
or null if no such edge existsIllegalArgumentException - if node1 or node2
are null or not legal nodes in the graphNodeIterable getNodes()
EdgeIterable getEdges()
If the graph is undirected, directed mutual edges will be present only once.
NodeIterable getNeighbors(Node node)
node. Neighbors are nodes connected to
node with any edge of the graph. Neighbors exclude node itself,
therefore self-loops are ignored.node - the node whose neighbors are to be returnednode's neighborsIllegalArgumentException - if node is null
or not legal in the graph.EdgeIterable getEdges(Node node)
node.
For directed graph, note that self-loops are repeated only once. Undirected graphs repeats edges once by default.
node - the node whose incident edges are to be returnednodeIllegalArgumentException - if node is null
or not legal in the graph.int getNodeCount()
Special case of interest:
Warning: This method is not thread safe, be sure to call it in a locked statement.
int getEdgeCount()
Special case of interest:
Warning: This method is not thread safe, be sure to call it in a locked statement.
int getNodeVersion()
External modules can compare local copy of version to determine if update is necessary.
int getEdgeVersion()
External modules can compare local copy of version to determine if update is necessary.
Node getOpposite(Node node, Edge edge)
node through edge.node - the node whose adjacent node is to be returnededge - the edge whose the opposite node is to be returnednode through edgeIllegalArgumentException - if node or edge is null,
or if node is not incident to edgeint getDegree(Node node)
node. Self-loops are counted twice for directed graphs.node - the node whose degree is to be returned
Warning: This method is not thread safe, be sure to call it in a locked statement.
nodeIllegalArgumentException - if node is null or not legal in the graphboolean isSelfLoop(Edge edge)
true if edge is a self-loop.edge - the edge to be queriedtrue if edge is a self-loop, false otherwiseIllegalArgumentException - if edge is null or adjacent nodes not
legal in the graphboolean isDirected(Edge edge)
true if edge is a directed edge in the current graph. Always
returns true when the graph is directed and false when the graph
is undirected. In case of a mixed graph returns Edge.isDirected().edge - true is edge is directedIllegalArgumentException - if edge is null or adjacent nodes not
legal in the graphboolean isAdjacent(Node node1, Node node2)
true if node1 is adjacent to node2. Is adjacent
when an edge exists between node1 and node2.
Warning: This method is not thread safe, be sure to call it in a locked statement.
node1 - the first node to be queriednode2 - the seconde node to be queriedtrue if node1 is adjacent to node2IllegalArgumentException - if node1 or node2 is null of
not legal in the graphboolean isAdjacent(Edge edge1, Edge edge2)
true if edge1 is adjacent to edge2. Is adjacent
when an node is incident to both edges.
Warning: This method is not thread safe, be sure to call it in a locked statement.
edge1 - the first node to be queriededge2 - the seconde node to be queriedtrue if edge1 is adjacent to edge2IllegalArgumentException - if edge1 or edge2 is null of
not legal in the graphvoid clearEdges(Node node)
node.node - the node whose edges is to be clearedIllegalArgumentException - if node if null or not legal in the graphIllegalMonitorStateException - if the current thread is holding a read lockvoid clear()
IllegalMonitorStateException - if the current thread is holding a read lockvoid clearEdges()
IllegalMonitorStateException - if the current thread is holding a read lockvoid setId(Node node, String id)
node. This identifier can be set
by users, in contrario of Node.getId() which is set by the system.id - the id that is to be set for nodevoid setId(Edge edge, String id)
edge. This identifier can be set
by users, in contrario of Edge.getId() which is set by the system.id - the id that is to be set for edgevoid readLock()
A read lock can be acquired several times by a thread, but be sure to call readUnlock()
the same number of time you called this method, or use readUnlockAll() to release all
locks.
ReentrantReadWriteLockvoid readUnlock()
Use readUnlockAll() if you ignore the number of times the read lock has been acquired.
void readUnlockAll()
void writeLock()
IllegalMonitorStateException - if the current thread is holding a read lockReentrantReadWriteLockvoid writeUnlock()
GraphModel getGraphModel()
GraphView getView()
Copyright © 2007-2012 Gephi Consortium. All Rights Reserved.