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

java.lang.Object
  extended by org.amino.ds.graph.AdjacentList<E>
Type Parameters:
E - Type of elements contained in AdjacentList
All Implemented Interfaces:
java.lang.Comparable<AdjacentList<E>>

public class AdjacentList<E>
extends java.lang.Object
implements java.lang.Comparable<AdjacentList<E>>

This class represents adjacent list, which is a frequently used method for storing graph.

Author:
Zhi Gan

Constructor Summary
AdjacentList(Node<E> head)
          Constructs an adjacent list with specified node as the head node.
 
Method Summary
 boolean addEdge(Edge<E> e)
          add a specified edge into this adjacent list.
 boolean addEdge(Node<E> node, double weight)
          add a edge into this adjacent list, with specified node and weight.
 int compareTo(AdjacentList<E> o)
          
 boolean containsEdge(E e)
          finds in this adjacent list whether there is an edge that has specified node value.
 boolean containsEdge(Node<E> e)
          finds whether the head node of this adjacent list links to the specified node e.
 boolean freeOwnership()
          free the ownership.
 java.util.Collection<Edge<E>> getEdge(E t)
          return all the edges whose one end has the value t in this adjacent list.
 java.util.Collection<Edge<E>> getEdge(Node<E> n)
          return all the edge linked to node n.
 Node<E> getHeadNode()
           
 java.util.Collection<Edge<E>> getLinkedEdges()
          get all linked edges implied by this adjacent list.
 java.util.List<AdjacentNode<E>> getLinkedNodes()
           
 boolean getOwnership()
           
 boolean removeEdge(E e)
          remove specified edge from this adjacent list.
 boolean removeEdge(Edge<E> e)
          remove a specified edge from this adjacent list.
 boolean removeEdge(Node<E> n)
          remove all edges connected to specified node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdjacentList

public AdjacentList(Node<E> head)
Constructs an adjacent list with specified node as the head node.

Parameters:
head - the head node of this adjacent list
Method Detail

getLinkedNodes

public java.util.List<AdjacentNode<E>> getLinkedNodes()
Returns:
the nodes adjacent to head node

getHeadNode

public Node<E> getHeadNode()
Returns:
head node of this adjacent list

addEdge

public boolean addEdge(Edge<E> e)
add a specified edge into this adjacent list.

Parameters:
e - edge to add
Returns:
true if successful, or false

addEdge

public boolean addEdge(Node<E> node,
                       double weight)
add a edge into this adjacent list, with specified node and weight.

Parameters:
node - the node connected with the head node of this adjacent list
weight - weight of the edge to add
Returns:
true if successful, or else

removeEdge

public boolean removeEdge(Edge<E> e)
remove a specified edge from this adjacent list.

Parameters:
e - the edge to remove
Returns:
true if successful, or false

removeEdge

public boolean removeEdge(Node<E> n)
remove all edges connected to specified node.

Parameters:
n - the node with edges to be removed
Returns:
true if any edge removed, or false

removeEdge

public boolean removeEdge(E e)
remove specified edge from this adjacent list.

Parameters:
e - the edge to remove
Returns:
true if successful, or false

getOwnership

public boolean getOwnership()
Returns:
true if ownership got, or false

freeOwnership

public boolean freeOwnership()
free the ownership.

Returns:
true if ownership freed

compareTo

public int compareTo(AdjacentList<E> o)

Specified by:
compareTo in interface java.lang.Comparable<AdjacentList<E>>

getEdge

public java.util.Collection<Edge<E>> getEdge(Node<E> n)
return all the edge linked to node n.

Parameters:
n - the target node
Returns:
the collection of edges linked to node n

getEdge

public java.util.Collection<Edge<E>> getEdge(E t)
return all the edges whose one end has the value t in this adjacent list.

Parameters:
t - target value
Returns:
the collection of edges

containsEdge

public boolean containsEdge(E e)
finds in this adjacent list whether there is an edge that has specified node value.

Parameters:
e - target value
Returns:
true if edge exists, or false

containsEdge

public boolean containsEdge(Node<E> e)
finds whether the head node of this adjacent list links to the specified node e.

Parameters:
e - target node
Returns:
true if the edge exists, or false

getLinkedEdges

public java.util.Collection<Edge<E>> getLinkedEdges()
get all linked edges implied by this adjacent list.

Returns:
the collection of edges


Copyright © 2008. All Rights Reserved.