|
Gephi Toolkit Javadoc | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Graph
Main interface for accessing the graph structure and develop algorithms.
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 EdgeIterable
readUnlockAll()
to release all the locks.
Note: Write locking is automatically done when modifying th graph (add, remove, ...).
Method Summary | |
---|---|
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(java.lang.String id)
Returns the edge with identifier equals to id . |
int |
getEdgeCount()
Returns the number of edges in the graph Special case of interest: Count self-loops once only. |
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(java.lang.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,
java.lang.String id)
Sets the string identifier of edge . |
void |
setId(Node node,
java.lang.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. |
Method Detail |
---|
boolean 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 add
java.lang.IllegalArgumentException
- 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,
java.lang.IllegalMonitorStateException
- if the current thread is holding a read lockboolean addNode(Node node)
node
- the node to add
java.lang.IllegalArgumentException
- if node
is null
java.lang.IllegalMonitorStateException
- 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 remove
java.lang.IllegalArgumentException
- if edge
is null
or nodes not legal in
the graph
java.lang.IllegalMonitorStateException
- 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 remove
java.lang.IllegalArgumentException
- if node
is null
or not legal in the graph.
java.lang.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 required
node
java.lang.IllegalArgumentException
- if node
is null
boolean 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 required
edge
java.lang.IllegalArgumentException
- if edge
is null
Node 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 number
id
, or null
if not foundNode getNode(java.lang.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, unique
id
, 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 number
id
, or null
if not foundEdge getEdge(java.lang.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, unique
id
, 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 edge
node1
and node2
or null
if no such edge exists
java.lang.IllegalArgumentException
- 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 returned
node
's neighbors
java.lang.IllegalArgumentException
- 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 returned
node
java.lang.IllegalArgumentException
- 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 returned
node
through edge
java.lang.IllegalArgumentException
- if node
or edge
is null
,
or if node
is not incident to edge
int 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.
node
java.lang.IllegalArgumentException
- 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 queried
true
if edge
is a self-loop, false
otherwise
java.lang.IllegalArgumentException
- 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 directed
java.lang.IllegalArgumentException
- 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 queried
true
if node1
is adjacent to node2
java.lang.IllegalArgumentException
- 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 queried
true
if edge1
is adjacent to edge2
java.lang.IllegalArgumentException
- if edge1
or edge2
is null
of
not legal in the graphvoid clearEdges(Node node)
node
.
node
- the node whose edges is to be cleared
java.lang.IllegalArgumentException
- if node
if null or not legal in the graph
java.lang.IllegalMonitorStateException
- if the current thread is holding a read lockvoid clear()
java.lang.IllegalMonitorStateException
- if the current thread is holding a read lockvoid clearEdges()
java.lang.IllegalMonitorStateException
- if the current thread is holding a read lockvoid setId(Node node, java.lang.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 node
void setId(Edge edge, java.lang.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 edge
void 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.
ReentrantReadWriteLock
void readUnlock()
Use readUnlockAll()
if you ignore the number of times the read lock has been acquired.
void readUnlockAll()
void writeLock()
java.lang.IllegalMonitorStateException
- if the current thread is holding a read lockReentrantReadWriteLock
void writeUnlock()
GraphModel getGraphModel()
GraphView getView()
|
Gephi Toolkit Javadoc | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |