public interface Network
Defines a network / graph data structure that contains Nodes with connections between them called edges or Links. This is just the interface to access and manipulate network structures provided by existing implementations.
Node
and Link
objects should be created using the
respective network instance using createNode
and
createLink
methods. This avoids dealing with specific
Node or Link implementations.
Note: by creating a new node or link you are not adding them to the
network. You still have to use addNode
or
addLink
.
This library uses Guice
to deal with network instance creation, hence, rather than worrying about
specific implementations, a user can just request Network
instances from Guice as follows:
Injector injector = Guice.createInjector(new NetworkModule());
Network network = injector.getInstance(Network.class);
Node
,
Link
,
NetworkModule
Modifier and Type | Method and Description |
---|---|
Link |
addLink(Node node1,
Node node2)
Adds a Link to the graph.
|
boolean |
addLink(Node node1,
Node node2,
Link link)
Creates and adds a link to the network between the given nodes.
|
boolean |
addNode(Node node)
Adds a node to the network.
|
boolean |
containsDirectedLink(Node node1,
Node node2)
Returns true of the given link is in the network.
|
boolean |
containsLink(Link link)
Returns true of the given link is in the network.
|
boolean |
containsLink(Node node1,
Node node2)
Returns true of the given link is in the network.
|
boolean |
containsNode(Node node)
Returns true of the given node is in the network.
|
Link |
createLink()
Creates a new link that can be added to the network.
|
Node |
createNode()
Creates a new node that can be added to the network.
|
java.util.Collection<? extends Link> |
getInLinks(Node node)
Returns a collection of links coming to the given node from other
nodes.
|
Link |
getLink(int id)
Returns a link by its Integer id or null if the node does not exist.
|
Link |
getLink(Node node1,
Node node2)
Returns a link given the two nodes it connects.
|
int |
getLinkCount()
Returns the number of links in the network.
|
java.util.Collection<? extends Link> |
getLinks()
Returns a collection of all the links in the network.
|
java.util.Collection<? extends Link> |
getLinks(Node node)
Returns a collection of links attached to the given node.
|
java.util.Collection<? extends Node> |
getNeighbours(int id)
Returns a collection of nodes attached to the node with the given id by
some link.
|
java.util.Collection<? extends Node> |
getNeighbours(Node node)
Returns a collection of nodes attached to the given node by some link.
|
Node |
getNode(int id)
Returns a node by its Integer id or null if the node does not exist.
|
int |
getNodeCount()
Returns the number of nodes in the network.
|
java.util.Collection<? extends Node> |
getNodes()
Returns a collection of all the nodes in the network.
|
org.apache.commons.lang3.tuple.Pair<Node,Node> |
getNodes(int linkID)
Returns the two nodes attached to a link with the given id.
|
org.apache.commons.lang3.tuple.Pair<Node,Node> |
getNodes(Link link)
Returns the two nodes that the given link connects.
|
java.util.Collection<? extends Link> |
getOutLinks(Node node)
Returns a collection of links coming from the given node to other
nodes.
|
java.util.Collection<? extends Node> |
getPredecessors(Node node)
Returns a collection of nodes attached to links coming to the given node.
|
java.util.Collection<? extends Node> |
getSuccessors(Node node)
Returns a collection of nodes attached to link coming from the given
node.
|
boolean |
removeLink(int id)
Removes a link from the network based on its id.
|
boolean |
removeLink(Link link)
Removes a link from the network.
|
boolean |
removeNode(int id)
Removes a node from the network based on its ID.
|
boolean |
removeNode(Node node)
Removes a node from the network.
|
boolean addNode(Node node)
node
- the node to be addedLink addLink(Node node1, Node node2)
node1
- an existing node within the networknode2
- an existing node within the networkboolean addLink(Node node1, Node node2, Link link)
node1
- an existing node within the networknode2
- an existing node within the networklink
- a link to be added from node1 to node2boolean removeNode(Node node)
node
- the node to be removedboolean removeNode(int id)
id
- the id of the node to be removedboolean removeLink(Link link)
link
- the link to be removedboolean removeLink(int id)
id
- the id of the link to be removedNode getNode(int id)
id
- the id of the node to be returnedLink getLink(int id)
id
- the id of the link to be returnedLink getLink(Node node1, Node node2)
node1
- a node attached to the start of the linknode2
- a node attached to the end of the linkjava.util.Collection<? extends Link> getLinks(Node node)
node
- the node from which we wish to extract the links from.java.util.Collection<? extends Link> getOutLinks(Node node)
node
- the node from which we wish to extract the links from.java.util.Collection<? extends Link> getInLinks(Node node)
node
- the node from which we wish to extract the links from.java.util.Collection<? extends Node> getSuccessors(Node node)
node
- the current node we want the successors fromjava.util.Collection<? extends Node> getPredecessors(Node node)
node
- the current node we want the predecessors fromjava.util.Collection<? extends Node> getNeighbours(Node node)
node
- the node we want the neighbours from.java.util.Collection<? extends Node> getNeighbours(int id)
id
- the id of the node we want the neighbours from.java.util.Collection<? extends Node> getNodes()
java.util.Collection<? extends Link> getLinks()
org.apache.commons.lang3.tuple.Pair<Node,Node> getNodes(int linkID)
linkID
- the id of the link from which we want to retrieve the nodes.(from org.apache.commons.lang3.tuple.Pair )
org.apache.commons.lang3.tuple.Pair<Node,Node> getNodes(Link link)
link
- the link from which we want to extract the nodes.(from org.apache.commons.lang3.tuple.Pair )
int getNodeCount()
int getLinkCount()
boolean containsNode(Node node)
node
- a node we want to checkboolean containsLink(Link link)
link
- a link we want to checkboolean containsLink(Node node1, Node node2)
node1
- one of the nodes for the linknode2
- one of the nodes for the linkboolean containsDirectedLink(Node node1, Node node2)
node1
- one of the nodes for the linknode2
- one of the nodes for the linkNode createNode()
Node