jcommon.graph.impl
Class AdjacencyList<TVertex extends IVertex<TValue>,TValue,TProcessedValue>

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

public class AdjacencyList<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
extends Object
implements IAdjacencyList<TVertex,TValue,TProcessedValue>

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.
 Map<TValue,TProcessedValue> createResultMap()
          Creates an instance of a Map that's properly sized for holding a mapping of values to their processed result.
 Set<TVertex> getEndingVertices()
          Provides a Set that contains vertices who have no out neighbors.
 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.
 boolean isEndingVertex(TVertex vertex)
          Determines if the provided vertex parameter is in the set of ending vertices.
 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)
See Also:
IAdjacencyList
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<TValue>,TValue,TProcessedValue>
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<TValue>,TValue,TProcessedValue>
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<TValue>,TValue,TProcessedValue>
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<TValue>,TValue,TProcessedValue>
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<TValue>,TValue,TProcessedValue>
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<TValue>,TValue,TProcessedValue>
Returns:
An int representing the size of the IAdjacencyList.

getEndingVertices

public Set<TVertex> getEndingVertices()
Description copied from interface: IAdjacencyList
Provides a Set that contains vertices who have no out neighbors.

Specified by:
getEndingVertices in interface IAdjacencyList<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
A Set containing vertices with no out neighbors.

iterator

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

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<TValue>,TValue,TProcessedValue>
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.

isEndingVertex

public boolean isEndingVertex(TVertex vertex)
Description copied from interface: IAdjacencyList
Determines if the provided vertex parameter is in the set of ending vertices.

Specified by:
isEndingVertex in interface IAdjacencyList<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
vertex - The vertex for whom you wish to test for set membership.
Returns:
true if the vertex is in the set of ending vertices; false otherwise.
See Also:
IAdjacencyList.getEndingVertices()

createResultMap

public Map<TValue,TProcessedValue> createResultMap()
Description copied from interface: IAdjacencyList
Creates an instance of a Map that's properly sized for holding a mapping of values to their processed result.

Specified by:
createResultMap in interface IAdjacencyList<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
An instance of Map mapping values to their processed result.


Copyright © 2012-2013. All Rights Reserved.