org.amino.ds.graph
Class DirectedGraphImpl<E>

java.lang.Object
  extended by org.amino.ds.graph.AbstractGraph<E>
      extended by org.amino.ds.graph.DirectedGraphImpl<E>
Type Parameters:
E - Type of element in graph nodes
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, DirectedGraph<E>, Graph<E>

public class DirectedGraphImpl<E>
extends AbstractGraph<E>
implements DirectedGraph<E>

Sample implementation of interface DirectedGraph. This graph is based on adjacent list expression.


Constructor Summary
DirectedGraphImpl()
           
 
Method Summary
 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.
 Graph<E> clone()
          Clone this graph.
 java.util.Collection<Node<E>> getDestinations(Node<E> node)
          Get nodes started with start node.
 java.util.Collection<Edge<E>> getIncoming(Node<E> node)
          Get edges ended with end node.
 java.util.Collection<Edge<E>> getOutgoing(Node<E> node)
          Get edges started with start node.
 java.util.Collection<Node<E>> getSources(Node<E> node)
          Get nodes end with end node.
 java.util.Collection<AdjacentNode<E>> getWeightDestinations(Node<E> start)
          Get weighted edges started with start node.
 java.util.Collection<AdjacentNode<E>> getWeightSources(Node<E> end)
          Get weighted edges ended with end node.
 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 class org.amino.ds.graph.AbstractGraph
add, addAll, addAllNodes, addNode, addNode, clear, contains, containsAll, containsEdge, containsNode, dumpGraph, freeMultiOwnerShip, getAllNodes, getEdges, getEdges, getLinkedEdges, getLinkedNodes, getMultiOwnerShip, getNodes, isEmpty, iterator, remove, removeAll, retainAll, simpleContentionManager, simpleContentionManager, size, toArray, toArray
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.amino.ds.graph.Graph
addAllNodes, addNode, addNode, containsEdge, containsNode, getAllNodes, getEdges, getEdges, getLinkedEdges, getLinkedNodes, getNodes
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

DirectedGraphImpl

public DirectedGraphImpl()
Method Detail

addEdge

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

Specified by:
addEdge in interface Graph<E>
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

removeEdge

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

Specified by:
removeEdge in interface Graph<E>
Parameters:
start - start node
end - end node
Returns:
true if the operation is successful

removeEdge

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

Specified by:
removeEdge in interface Graph<E>
Parameters:
start - start value
end - end value
Returns:
true if the operation is successful

removeEdge

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

Specified by:
removeEdge in interface Graph<E>
Parameters:
edge - edge removed
Returns:
true if the operation is successful

addEdge

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

Specified by:
addEdge in interface Graph<E>
Parameters:
edge - adding edge
Returns:
true if succeed

addEdge

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

Specified by:
addEdge in interface Graph<E>
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

getDestinations

public java.util.Collection<Node<E>> getDestinations(Node<E> node)
Get nodes started with start node.

Specified by:
getDestinations in interface DirectedGraph<E>
Parameters:
node - start node
Returns:
collection of nodes started with start node

getIncoming

public java.util.Collection<Edge<E>> getIncoming(Node<E> node)
Get edges ended with end node.

Specified by:
getIncoming in interface DirectedGraph<E>
Parameters:
node - end node
Returns:
collection of edges ended with node

getOutgoing

public java.util.Collection<Edge<E>> getOutgoing(Node<E> node)
Get edges started with start node.

Specified by:
getOutgoing in interface DirectedGraph<E>
Parameters:
node - start node
Returns:
collection of edges started with start node

getSources

public java.util.Collection<Node<E>> getSources(Node<E> node)
Get nodes end with end node.

Specified by:
getSources in interface DirectedGraph<E>
Parameters:
node - end node
Returns:
collection of nodes ended with end node

clone

public Graph<E> clone()
Clone this graph.

Specified by:
clone in interface Graph<E>
Specified by:
clone in class AbstractGraph<E>
Returns:
a graph

removeNode

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

Specified by:
removeNode in interface Graph<E>
Overrides:
removeNode in class AbstractGraph<E>
Parameters:
node - node removed
Returns:
true if the operation is successful

getWeightDestinations

public java.util.Collection<AdjacentNode<E>> getWeightDestinations(Node<E> start)
Get weighted edges started with start node.

Specified by:
getWeightDestinations in interface DirectedGraph<E>
Parameters:
start - start node
Returns:
collection of weighted edges started with start node

getWeightSources

public java.util.Collection<AdjacentNode<E>> getWeightSources(Node<E> end)
Get weighted edges ended with end node.

Specified by:
getWeightSources in interface DirectedGraph<E>
Parameters:
end - end node
Returns:
collection of weighted edges ended with end node


Copyright © 2008. All Rights Reserved.