Package org.gephi.graph.api
Interface Graph
-
- All Known Subinterfaces:
DirectedGraph
,DirectedSubgraph
,Subgraph
,UndirectedGraph
,UndirectedSubgraph
public interface Graph
Graph interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
addAllEdges(Collection<? extends Edge> edges)
Adds all edges in the collection to this graph.boolean
addAllNodes(Collection<? extends Node> nodes)
Adds all nodes in the collection to this graph.boolean
addEdge(Edge edge)
Adds an edge to this graph.boolean
addNode(Node node)
Adds a node to this graph.void
clear()
Clears all edges and all nodes in the graphvoid
clearEdges()
Clears all edges in the graphvoid
clearEdges(Node node)
Clears the edges incident to the given node.void
clearEdges(Node node, int type)
Clears the edges of the given type incident to the given node.boolean
contains(Edge edge)
Returns true if edge is contained in this graph.boolean
contains(Node node)
Returns true if node is contained in this graph.Object
getAttribute(String key)
Gets the attribute value for the given key.Object
getAttribute(String key, double timestamp)
Gets the attribute for the given key and timestampObject
getAttribute(String key, Interval interval)
Gets the attribute for the given key and intervalSet<String>
getAttributeKeys()
Gets all attribute keys.int
getDegree(Node node)
Gets the node degree.Edge
getEdge(Object id)
Gets an edge by its identifier.Edge
getEdge(Node node1, Node node2)
Gets the edge adjacent to node1 and node2.Edge
getEdge(Node node1, Node node2, int type)
Gets the edge adjacent to node1 and node2 and from the given type.int
getEdgeCount()
Gets the number of edges in the graph.int
getEdgeCount(int type)
Gets the number of edges of the given type in the graph.EdgeIterable
getEdges()
Gets all the edges in the graph.EdgeIterable
getEdges(int type)
Gets all the edges of a particular type in the graph.EdgeIterable
getEdges(Node node)
Gets all edges incident to a given node.EdgeIterable
getEdges(Node node, int type)
Gets all edges incident to a given node with the given edge type.EdgeIterable
getEdges(Node node1, Node node2)
Get the edges adjacent to node1 and node2.EdgeIterable
getEdges(Node node1, Node node2, int type)
Gets the edges adjacent to node1 and node 2 and from the given type.GraphLock
getLock()
Returns the graph lock, in case locking is enabled.GraphModel
getModel()
Returns the model this graph belongs to.NodeIterable
getNeighbors(Node node)
Gets all neighbors of a given node.NodeIterable
getNeighbors(Node node, int type)
Gets all neighbors of a given node connected through the given edge type.Node
getNode(Object id)
Gets a node given its identifier.int
getNodeCount()
Gets the number of nodes in the graph.NodeIterable
getNodes()
Gets all the nodes in the graph.Node
getOpposite(Node node, Edge edge)
Gets the node at the opposite end of the given edge.EdgeIterable
getSelfLoops()
Gets all the self-loop edges in the graph.int
getVersion()
Returns a version number for this graph.GraphView
getView()
Gets the graph view associated to this graph.boolean
hasEdge(Object id)
Returns true if an edge with id as identifier exists.boolean
hasNode(Object id)
Returns true if a node with id as identifier exists.boolean
isAdjacent(Node node1, Node node2)
Returns true if node1 and node2 are adjacent.boolean
isAdjacent(Node node1, Node node2, int type)
Returns true if node1 and node2 are adjacent with an edge of the given type.boolean
isDirected()
Returns true if this graph is directed.boolean
isDirected(Edge edge)
Returns true if the given edge is directed.boolean
isIncident(Edge edge1, Edge edge2)
Returns true if edge1 and edge2 are incident.boolean
isIncident(Node node, Edge edge)
Returns true if the node and the edge are incident.boolean
isMixed()
Returns true if this graph is mixed (both directed and undirected edges).boolean
isSelfLoop(Edge edge)
Returns true if the given edge is a self-loop.boolean
isUndirected()
Returns true if this graph is undirected.void
readLock()
Opens a read lock for the current thread.void
readUnlock()
Closes a read lock for the current thread.void
readUnlockAll()
Closes all read locks for the current thread.boolean
removeAllEdges(Collection<? extends Edge> edges)
Removes all edges in the collection from this graph.boolean
removeAllNodes(Collection<? extends Node> nodes)
Removes all nodes in the collection from this graph.void
removeAttribute(String key)
Removes the attribute for the given key.void
removeAttribute(String key, double timestamp)
Removes the attribute for the given key and timestamp.void
removeAttribute(String key, Interval interval)
Removes the attribute for the given key and interval.boolean
removeEdge(Edge edge)
Removes an edge from this graph.boolean
removeNode(Node node)
Removes a node from this graph.void
setAttribute(String key, Object value)
Sets the attribute value for the given key.void
setAttribute(String key, Object value, double timestamp)
Sets the attribute value for the given key and timestamp.void
setAttribute(String key, Object value, Interval interval)
Sets the attribute value for the given key and interval.void
writeLock()
Opens a write lock for the current thread.void
writeUnlock()
Closes a write lock for the current thread.
-
-
-
Method Detail
-
addEdge
boolean addEdge(Edge edge)
Adds an edge to this graph.- Parameters:
edge
- the edge to add- Returns:
- true if the edge has been added, false if it already exists
-
addNode
boolean addNode(Node node)
Adds a node to this graph.- Parameters:
node
- the node to add- Returns:
- true if the node has been added, false if it already exists
-
addAllEdges
boolean addAllEdges(Collection<? extends Edge> edges)
Adds all edges in the collection to this graph.- Parameters:
edges
- the edge collection- Returns:
- true if at least one edge has been added, false otherwise
-
addAllNodes
boolean addAllNodes(Collection<? extends Node> nodes)
Adds all nodes in the collection to this graph.- Parameters:
nodes
- the node collection- Returns:
- true if at least one node has been added, false otherwise
-
removeEdge
boolean removeEdge(Edge edge)
Removes an edge from this graph.- Parameters:
edge
- the edge to remove- Returns:
- true if the edge was removed, false if it didn't exist
-
removeNode
boolean removeNode(Node node)
Removes a node from this graph.All edges attached to the node will be removed as well.
- Parameters:
node
- the node to remove- Returns:
- true if the node was removed, false if it didn't exist
-
removeAllEdges
boolean removeAllEdges(Collection<? extends Edge> edges)
Removes all edges in the collection from this graph.- Parameters:
edges
- the edge collection- Returns:
- true if at least one edge has been removed, false otherwise
-
removeAllNodes
boolean removeAllNodes(Collection<? extends Node> nodes)
Removes all nodes in the collection from this graph.- Parameters:
nodes
- the node collection- Returns:
- true if at least one node has been removed, false otherwise
-
contains
boolean contains(Node node)
Returns true if node is contained in this graph.- Parameters:
node
- the node to test- Returns:
- true if this graph contains node, false otherwise
-
contains
boolean contains(Edge edge)
Returns true if edge is contained in this graph.- Parameters:
edge
- the edge to test- Returns:
- true if this graph contains edge, false otherwise
-
getNode
Node getNode(Object id)
Gets a node given its identifier.- Parameters:
id
- the node id- Returns:
- the node, or null if not found
-
hasNode
boolean hasNode(Object id)
Returns true if a node with id as identifier exists.- Parameters:
id
- node id- Returns:
- true if a node exists, false otherwise
-
getEdge
Edge getEdge(Object id)
Gets an edge by its identifier.- Parameters:
id
- the edge id- Returns:
- the edge, or null if not found
-
hasEdge
boolean hasEdge(Object id)
Returns true if an edge with id as identifier exists.- Parameters:
id
- edge id- Returns:
- true if an edge exists, false otherwise
-
getEdge
Edge getEdge(Node node1, Node node2)
Gets the edge adjacent to node1 and node2.If multiple parallel edges exist it returns the first edge.
- Parameters:
node1
- first nodenode2
- second node- Returns:
- adjacent edge, or null if not found
-
getEdges
EdgeIterable getEdges(Node node1, Node node2)
Get the edges adjacent to node1 and node2.If there aren't any parallel edges only one edge will be returned.
- Parameters:
node1
- first nodenode2
- second node- Returns:
- adjacent edges
-
getEdge
Edge getEdge(Node node1, Node node2, int type)
Gets the edge adjacent to node1 and node2 and from the given type.If multiple parallel edges exist it returns the first edge.
- Parameters:
node1
- the first nodenode2
- the second nodetype
- the edge type- Returns:
- the adjacent edge, or null if not found
-
getEdges
EdgeIterable getEdges(Node node1, Node node2, int type)
Gets the edges adjacent to node1 and node 2 and from the given type.If there aren't any parallel edges only one edge will be returned.
- Parameters:
node1
- the first nodenode2
- the second nodetype
- the edge type- Returns:
- the adjacent edges, or an empty iterator if not found
-
getNodes
NodeIterable getNodes()
Gets all the nodes in the graph.- Returns:
- a node iterable over all nodes
-
getEdges
EdgeIterable getEdges()
Gets all the edges in the graph.- Returns:
- an edge iterable over all edges
-
getEdges
EdgeIterable getEdges(int type)
Gets all the edges of a particular type in the graph.- Parameters:
type
- edge type- Returns:
- an edge iterable over all edges of this type
-
getSelfLoops
EdgeIterable getSelfLoops()
Gets all the self-loop edges in the graph.- Returns:
- an edge iterable over all self-loops
-
getNeighbors
NodeIterable getNeighbors(Node node)
Gets all neighbors of a given node.- Parameters:
node
- the node to get neighbors- Returns:
- a node iterable over the neighbors
-
getNeighbors
NodeIterable getNeighbors(Node node, int type)
Gets all neighbors of a given node connected through the given edge type.- Parameters:
node
- the node to get neighborstype
- the edge type- Returns:
- a node iterable over the neigbors
-
getEdges
EdgeIterable getEdges(Node node)
Gets all edges incident to a given node.- Parameters:
node
- the node to get edges from- Returns:
- an edge iterable of all edges connected to the node
-
getEdges
EdgeIterable getEdges(Node node, int type)
Gets all edges incident to a given node with the given edge type.- Parameters:
node
- the node to get edges fromtype
- the edge type- Returns:
- an edge iterable of the edges connected to the node
-
getNodeCount
int getNodeCount()
Gets the number of nodes in the graph.- Returns:
- the node count
-
getEdgeCount
int getEdgeCount()
Gets the number of edges in the graph.- Returns:
- the edge count
-
getEdgeCount
int getEdgeCount(int type)
Gets the number of edges of the given type in the graph.- Parameters:
type
- the edge type- Returns:
- the edge count for the given type
-
getOpposite
Node getOpposite(Node node, Edge edge)
Gets the node at the opposite end of the given edge.- Parameters:
node
- the node to get the oppositeedge
- the edge connected to both nodes- Returns:
- the opposite node
-
getDegree
int getDegree(Node node)
Gets the node degree.- Parameters:
node
- the node- Returns:
- the degree
-
isSelfLoop
boolean isSelfLoop(Edge edge)
Returns true if the given edge is a self-loop.- Parameters:
edge
- the edge to test- Returns:
- true if self-loop, false otherwise
-
isDirected
boolean isDirected(Edge edge)
Returns true if the given edge is directed.- Parameters:
edge
- the edge to test- Returns:
- true if directed, false otherwise
-
isAdjacent
boolean isAdjacent(Node node1, Node node2)
Returns true if node1 and node2 are adjacent.- Parameters:
node1
- the first nodenode2
- the second node- Returns:
- true if node1 is adjacent to node2, false otherwise
-
isAdjacent
boolean isAdjacent(Node node1, Node node2, int type)
Returns true if node1 and node2 are adjacent with an edge of the given type.- Parameters:
node1
- the first nodenode2
- the second nodetype
- the edge type- Returns:
- true if node1 and node2 are adjacent with an edge og the given type, false otherwise
-
isIncident
boolean isIncident(Edge edge1, Edge edge2)
Returns true if edge1 and edge2 are incident.- Parameters:
edge1
- the first edgeedge2
- the second edge- Returns:
- true if edge1 is incident to edge2, false otherwise
-
isIncident
boolean isIncident(Node node, Edge edge)
Returns true if the node and the edge are incident.- Parameters:
node
- the nodeedge
- the edge- Returns:
- true if the node and edge are incident, false otherwise
-
clearEdges
void clearEdges(Node node)
Clears the edges incident to the given node.- Parameters:
node
- the node to clear edges from
-
clearEdges
void clearEdges(Node node, int type)
Clears the edges of the given type incident to the given node.- Parameters:
node
- the node to clear edges fromtype
- the edge type
-
clear
void clear()
Clears all edges and all nodes in the graph
-
clearEdges
void clearEdges()
Clears all edges in the graph
-
getView
GraphView getView()
Gets the graph view associated to this graph.- Returns:
- the graph view
-
getAttribute
Object getAttribute(String key)
Gets the attribute value for the given key.- Parameters:
key
- the key- Returns:
- the attribute value, or null if not found
-
getAttribute
Object getAttribute(String key, double timestamp)
Gets the attribute for the given key and timestamp- Parameters:
key
- the keytimestamp
- the timestamp- Returns:
- the attribute value, or null if not found
-
getAttribute
Object getAttribute(String key, Interval interval)
Gets the attribute for the given key and interval- Parameters:
key
- the keyinterval
- the interval- Returns:
- the attribute value, or null if not found
-
setAttribute
void setAttribute(String key, Object value)
Sets the attribute value for the given key.- Parameters:
key
- the keyvalue
- the value
-
removeAttribute
void removeAttribute(String key)
Removes the attribute for the given key.- Parameters:
key
- key
-
setAttribute
void setAttribute(String key, Object value, double timestamp)
Sets the attribute value for the given key and timestamp.- Parameters:
key
- the keyvalue
- the valuetimestamp
- the timestamp
-
setAttribute
void setAttribute(String key, Object value, Interval interval)
Sets the attribute value for the given key and interval.- Parameters:
key
- the keyvalue
- the valueinterval
- the interval
-
removeAttribute
void removeAttribute(String key, double timestamp)
Removes the attribute for the given key and timestamp.- Parameters:
key
- keytimestamp
- timestamp
-
removeAttribute
void removeAttribute(String key, Interval interval)
Removes the attribute for the given key and interval.- Parameters:
key
- keyinterval
- interval
-
getAttributeKeys
Set<String> getAttributeKeys()
Gets all attribute keys.- Returns:
- a set of all attribute keys
-
getModel
GraphModel getModel()
Returns the model this graph belongs to.- Returns:
- graph model
-
getVersion
int getVersion()
Returns a version number for this graph.The version gets altered when the graph structure changes.
- Returns:
- graph version
- See Also:
for a more sophisticated way to track changes
-
isDirected
boolean isDirected()
Returns true if this graph is directed.- Returns:
- true if directed, false otherwise
-
isUndirected
boolean isUndirected()
Returns true if this graph is undirected.- Returns:
- true if undirected, false otherwise
-
isMixed
boolean isMixed()
Returns true if this graph is mixed (both directed and undirected edges).- Returns:
- true if mixed, false otherwise
-
readLock
void readLock()
Opens a read lock for the current thread.
-
readUnlock
void readUnlock()
Closes a read lock for the current thread.
-
readUnlockAll
void readUnlockAll()
Closes all read locks for the current thread.
-
writeLock
void writeLock()
Opens a write lock for the current thread.
-
writeUnlock
void writeUnlock()
Closes a write lock for the current thread.
-
getLock
GraphLock getLock()
Returns the graph lock, in case locking is enabled. The graph lock controls the multi-thread access to the graph structure.- Returns:
- graph lock
-
-