jcommon.graph.impl
Class AdjacencyList<TVertex extends IVertex>

java.lang.Object
  extended by jcommon.graph.impl.AdjacencyList<TVertex>
All Implemented Interfaces:
Iterable<IAdjacencyListPair<TVertex>>, IAdjacencyList<TVertex>

public class AdjacencyList<TVertex extends IVertex>
extends Object
implements IAdjacencyList<TVertex>

See Also:
IAdjacencyList

Constructor Summary
AdjacencyList(Set<TVertex> vertices, Set<IEdge<TVertex>> edges)
           
 
Method Summary
 int[] calculateInDegrees()
          Calculates an integer array where the value at each index is the number of times that vertex is referenced elsewhere.
 int indexOf(IVertex vertex)
          Find the index in the IAdjacencyList at which the provided vertex argument can be found.
 boolean isEmpty()
          Determines if the adjacency list is empty.
 Iterator<IAdjacencyListPair<TVertex>> iterator()
           
 List<TVertex> outNeighborsAt(int index)
          Gets the list of out-neighbors for a given vertex of TVertex at the provided index argument.
 List<TVertex> outNeighborsFor(TVertex vertex)
          Gets the list of out-neighbors for a given vertex of TVertex.
 IAdjacencyListPair<TVertex> pairAt(int index)
          Retrieves an instance of IAdjacencyListPair at the specified index.
 int size()
          The size of the IAdjacencyList.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdjacencyList

public AdjacencyList(Set<TVertex> vertices,
                     Set<IEdge<TVertex>> edges)
Method Detail

calculateInDegrees

public int[] calculateInDegrees()
Calculates an integer array where the value at each index is the number of times that vertex is referenced elsewhere.

Specified by:
calculateInDegrees in interface IAdjacencyList<TVertex extends IVertex>
Returns:
An int array of size IAdjacencyList.size() representing the in-degrees for each vertex.

pairAt

public IAdjacencyListPair<TVertex> pairAt(int index)
Description copied from interface: IAdjacencyList
Retrieves an instance of IAdjacencyListPair at the specified index.

Specified by:
pairAt in interface IAdjacencyList<TVertex extends IVertex>
Parameters:
index - The index in the list for which we wish to get the associated IAdjacencyListPair.
Returns:
An instance of IAdjacencyListPair if found; otherwise null.
See Also:
IAdjacencyListPair

outNeighborsAt

public List<TVertex> outNeighborsAt(int index)
Description copied from interface: IAdjacencyList
Gets the list of out-neighbors for a given vertex of TVertex at the provided index argument.

Specified by:
outNeighborsAt in interface IAdjacencyList<TVertex extends IVertex>
Parameters:
index - The index in the list for which we wish to get the associated out-neighbors.
Returns:
A list of TVertex instances who are the out-neighbors for an instance of TVertex at the specified index.
See Also:
IAdjacencyListPair.getOutNeighbors()

outNeighborsFor

public List<TVertex> outNeighborsFor(TVertex vertex)
Description copied from interface: IAdjacencyList
Gets the list of out-neighbors for a given vertex of TVertex.

Specified by:
outNeighborsFor in interface IAdjacencyList<TVertex extends IVertex>
Parameters:
vertex - A vertex of TVertex for whom we wish to retrieve its out-neighbors.
Returns:
A list of TVertex instances who are the out-neighbors for the provided vertex argument.
See Also:
IAdjacencyListPair.getOutNeighbors()

isEmpty

public boolean isEmpty()
Description copied from interface: IAdjacencyList
Determines if the adjacency list is empty.

Specified by:
isEmpty in interface IAdjacencyList<TVertex extends IVertex>
Returns:
true if the adjacency list is empty; false otherwise.

size

public int size()
Description copied from interface: IAdjacencyList
The size of the IAdjacencyList. This is the same as the number of vertices in the IGraph.

Specified by:
size in interface IAdjacencyList<TVertex extends IVertex>
Returns:
An int representing the size of the IAdjacencyList.

iterator

public Iterator<IAdjacencyListPair<TVertex>> iterator()
Specified by:
iterator in interface Iterable<IAdjacencyListPair<TVertex extends IVertex>>

indexOf

public int indexOf(IVertex vertex)
Description copied from interface: IAdjacencyList
Find the index in the IAdjacencyList at which the provided vertex argument can be found.

Specified by:
indexOf in interface IAdjacencyList<TVertex extends IVertex>
Parameters:
vertex - An instance of IVertex of TVertex.
Returns:
The index in the IAdjacencyList at which the provided vertex argument can be found. -1 if the vertex cannot be found.


Copyright © 2012-2013. All Rights Reserved.