org.amino.ds.graph
Interface Graph<E>

Type Parameters:
E - Type of elements
All Superinterfaces:
java.lang.Cloneable, java.util.Collection<E>, java.lang.Iterable<E>
All Known Subinterfaces:
DirectedGraph<E>
All Known Implementing Classes:
AbstractGraph, DirectedGraphImpl, UndirectedGraph

public interface Graph<E>
extends java.util.Collection<E>, java.lang.Cloneable

A Graph provides basic operations to create, search and change itself.

Author:
Zhi Gan

Method Summary
 boolean addAllNodes(java.util.Collection<Node<E>> nodes)
          add all the nodes to graph.
 boolean addEdge(Edge<E> edge)
          Add an edge to this graph.
 boolean addEdge(E start, E end, double weight)
          add one edge to graph.
 boolean addEdge(Node<E> start, Node<E> end, double weight)
          add one edge to graph with weight.
 Node<E> addNode(E e)
          Add a node to graph, which contains value e.
 Node<E> addNode(Node<E> node)
          Add a node to graph, which contains value e.
 Graph<E> clone()
          Clone this graph.
 boolean containsEdge(E start, E end)
          Returns whether this graph contains an edge between start and end.
 boolean containsNode(Node<E> start)
          whether this graph contains the specified node.
 java.util.Collection<Node<E>> getAllNodes()
          get all the nodes in the graph.
 java.util.Collection<Edge<E>> getEdges(E start, E end)
          get all the edge start from the nodes which contain value start and end.
 java.util.Collection<Edge<E>> getEdges(Node<E> start, Node<E> end)
          get all all the edges which start from node start and end with node end.
 java.util.Collection<Edge<E>> getLinkedEdges(Node<E> node)
          get all edges directly linked to the specified node.
 java.util.Collection<AdjacentNode<E>> getLinkedNodes(Node<E> node)
          get all nodes which directly linked to node.
 java.util.Collection<Node<E>> getNodes(E e)
          get all nodes whose value equal to e.
 boolean removeEdge(Edge<E> edge)
          remove all the edges which start from start and end to end.
 boolean removeEdge(E start, E end)
          remove all the edges which start from start and end to end.
 boolean removeEdge(Node<E> start, Node<E> end)
          remove all the edges which start from start and end to end.
 boolean removeNode(Node<E> node)
          remove the node from the graph.
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Method Detail

getNodes

java.util.Collection<Node<E>> getNodes(E e)
get all nodes whose value equal to e.

Parameters:
e - value to be got
Returns:
a collection of nodes

getAllNodes

java.util.Collection<Node<E>> getAllNodes()
get all the nodes in the graph.

Returns:
a collection of all the nodes in the graph

getEdges

java.util.Collection<Edge<E>> getEdges(Node<E> start,
                                       Node<E> end)
get all all the edges which start from node start and end with node end.

Parameters:
start - the start node of the edge
end - the end node of the edge
Returns:
collection of all the edges which start from node start and end with node end

getEdges

java.util.Collection<Edge<E>> getEdges(E start,
                                       E end)
get all the edge start from the nodes which contain value start and end. to nodes which contain value end

Parameters:
start - start value
end - end value
Returns:
collection of all the edge start from the nodes which contain value start and end to nodes which contain value end

addNode

Node<E> addNode(E e)
Add a node to graph, which contains value e. If the tree already contains e, return the existing node instead of creating a new one.
FIXME: This method doesn't tell if a node is created or not. We need to add an boolean addIfAbsent(E e) method?

Parameters:
e - the value to add.
Returns:
a node in graph which contains the value

addNode

Node<E> addNode(Node<E> node)
Add a node to graph, which contains value e. If the tree already contains e, return the existing node instead of creating a new one.

Parameters:
node - the node to add
Returns:
return adding node if succeed. If there is already a graph node has the same value as node, return node in graph.

addAllNodes

boolean addAllNodes(java.util.Collection<Node<E>> nodes)
add all the nodes to graph.

Parameters:
nodes - nodes to be added
Returns:
true if the operation is successful

addEdge

boolean addEdge(E start,
                E end,
                double weight)
add one edge to graph.

Parameters:
start - value in start node. A new node will be added to graph is this value is not in graph yet.
end - value in end node. A new node will be added to graph is this value is not in graph yet.
weight - weight of this edge
Returns:
true if the operation is successful

addEdge

boolean addEdge(Node<E> start,
                Node<E> end,
                double weight)
add one edge to graph with weight.

Parameters:
start - start node. A new node will be added to graph is this value is not in graph yet.
end - end node. A new node will be added to graph is this value is not in graph yet.
weight - weight of this edge
Returns:
true if the operation is successful

addEdge

boolean addEdge(Edge<E> edge)
Add an edge to this graph.

Parameters:
edge - adding edge
Returns:
true if succeed

getLinkedNodes

java.util.Collection<AdjacentNode<E>> getLinkedNodes(Node<E> node)
get all nodes which directly linked to node.

Parameters:
node - start node
Returns:
collection of all linked nodes

getLinkedEdges

java.util.Collection<Edge<E>> getLinkedEdges(Node<E> node)
get all edges directly linked to the specified node.

Parameters:
node - start node
Returns:
collection of all linked edges

removeEdge

boolean removeEdge(Node<E> start,
                   Node<E> end)
remove all the edges which start from start and end to end.

Parameters:
start - start node
end - end node
Returns:
true if the operation is successful

removeEdge

boolean removeEdge(Edge<E> edge)
remove all the edges which start from start and end to end.

Parameters:
edge - edge removed
Returns:
true if the operation is successful

removeEdge

boolean removeEdge(E start,
                   E end)
remove all the edges which start from start and end to end.

Parameters:
start - start value
end - end value
Returns:
true if the operation is successful

removeNode

boolean removeNode(Node<E> node)
remove the node from the graph.

Parameters:
node - node removed
Returns:
true if the operation is successful

containsEdge

boolean containsEdge(E start,
                     E end)
Returns whether this graph contains an edge between start and end.

Parameters:
start - starting node of edge
end - ending node of edge
Returns:
true if this graph contains edge between start and end, false otherwise.

clone

Graph<E> clone()
               throws java.lang.CloneNotSupportedException
Clone this graph.

Returns:
a graph
Throws:
java.lang.CloneNotSupportedException - clone not supported

containsNode

boolean containsNode(Node<E> start)
whether this graph contains the specified node.

Parameters:
start - the node
Returns:
true if this graph contains the node


Copyright © 2008. All Rights Reserved.