org.javanetworkanalyzer.graphcreators
Class GraphCreator<V extends VId,E extends EdgeID>

java.lang.Object
  extended by org.javanetworkanalyzer.graphcreators.GraphCreator<V,E>
Type Parameters:
V - Vertex
E - Edge
Direct Known Subclasses:
WeightedGraphCreator

public class GraphCreator<V extends VId,E extends EdgeID>
extends Object

Creates JGraphT graphs from a csv file produced by OrbisGIS.

Author:
Adam Gouge

Field Summary
static int DIRECTED
          Specifies a directed graph.
protected static String DOUBLE_QUOTES
           
protected  Class<? extends E> edgeClass
          Edge class used for initializing the graph.
protected static String EMPTY_STRING
           
protected static String END_NODE
          End node column name.
protected static int endNodeIndex
          End node index.
protected  int orientation
          Orientation.
static int REVERSED
          Specifies a directed graph with reversed edge orientation.
protected static String SEPARATOR
          The csv produced by OrbisGIS uses a semicolon delimiter.
protected static String START_NODE
          Start node column name.
protected static int startNodeIndex
          Start node index.
static int UNDIRECTED
          Specifies an undirected graph.
protected  Class<? extends V> vertexClass
          Vertex class used for initializing the graph.
 
Constructor Summary
GraphCreator(String csvFile, int orientation, Class<? extends V> vertexClass, Class<? extends E> edgeClass)
          Initializes a new GraphCreator.
 
Method Summary
protected  String deleteDoubleQuotes(String s)
          Replaces " by the empty string.
protected  KeyedGraph<V,E> initializeGraph()
          Initializes a graph.
protected  void initializeIndices(Scanner scanner)
          Initialize the start node and end node indices by reading the first line of the csv file.
protected  E loadEdge(String[] row, KeyedGraph<V,E> graph, boolean reverse)
          Loads an edge into the graph.
 KeyedGraph<V,E> loadGraph()
          Returns a new graph from a csv file produced in OrbisGIS as the output.edges table given by ST_Graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

START_NODE

protected static final String START_NODE
Start node column name.

See Also:
Constant Field Values

END_NODE

protected static final String END_NODE
End node column name.

See Also:
Constant Field Values

orientation

protected final int orientation
Orientation.


vertexClass

protected final Class<? extends V extends VId> vertexClass
Vertex class used for initializing the graph.


edgeClass

protected final Class<? extends E extends EdgeID> edgeClass
Edge class used for initializing the graph.


startNodeIndex

protected static int startNodeIndex
Start node index.


endNodeIndex

protected static int endNodeIndex
End node index.


DIRECTED

public static final int DIRECTED
Specifies a directed graph.

See Also:
Constant Field Values

REVERSED

public static final int REVERSED
Specifies a directed graph with reversed edge orientation.

See Also:
Constant Field Values

UNDIRECTED

public static final int UNDIRECTED
Specifies an undirected graph.

See Also:
Constant Field Values

SEPARATOR

protected static final String SEPARATOR
The csv produced by OrbisGIS uses a semicolon delimiter.

See Also:
Constant Field Values

DOUBLE_QUOTES

protected static final String DOUBLE_QUOTES
See Also:
Constant Field Values

EMPTY_STRING

protected static final String EMPTY_STRING
See Also:
Constant Field Values
Constructor Detail

GraphCreator

public GraphCreator(String csvFile,
                    int orientation,
                    Class<? extends V> vertexClass,
                    Class<? extends E> edgeClass)
Initializes a new GraphCreator.

Parameters:
csvFile - CSV file containing the edge information.
orientation - The desired graph orientation.
vertexClass - The vertex class
edgeClass - The edge class
Method Detail

loadGraph

public KeyedGraph<V,E> loadGraph()
                                                     throws FileNotFoundException,
                                                            NoSuchMethodException
Returns a new graph from a csv file produced in OrbisGIS as the output.edges table given by ST_Graph.

Returns:
The graph.
Throws:
FileNotFoundException
NoSuchMethodException

initializeIndices

protected void initializeIndices(Scanner scanner)
Initialize the start node and end node indices by reading the first line of the csv file.

Parameters:
scanner - The scanner that will read the first line of the csv file.

deleteDoubleQuotes

protected String deleteDoubleQuotes(String s)
Replaces " by the empty string.

Parameters:
s - The String to be parsed.
Returns:
The given String with no quotes.

initializeGraph

protected KeyedGraph<V,E> initializeGraph()
                                                              throws NoSuchMethodException
Initializes a graph.

Returns:
The newly initialized graph
Throws:
NoSuchMethodException - If the vertex class does not have a constructor with just an Integer parameter.

loadEdge

protected E loadEdge(String[] row,
                     KeyedGraph<V,E> graph,
                     boolean reverse)
Loads an edge into the graph.

Parameters:
row - The row from which to load the edge.
graph - The graph to which the edges will be added.
reverse - true iff the edge orientation should be reversed.
Returns:
The newly loaded edge.


Copyright © 2014. All Rights Reserved.