List<?> linkFileList = linkFileReader.readAll();
BufferedReader graphFileReader = new BufferedReader( new FileReader( graphFile ) );
String line = graphFileReader.readLine();
DNVGraph graph = new DNVGraph();
if( line != null )
{
StringTokenizer lineTokenizer = new StringTokenizer( line );
int numberOfNodes = Integer.parseInt( lineTokenizer.nextToken() );
int numberOfLinks = Integer.parseInt( lineTokenizer.nextToken() );
if( numberOfNodes != nodeFileList.size() )
{
System.out.println( "WARNING: graph file does not match node file. graph file number of nodes = " + numberOfNodes
+ ". node file number of nodes = " + nodeFileList.size() );
}
if( numberOfLinks != linkFileList.size() )
{
System.out.println( "WARNING: graph file does not match link file. graph file number of links = " + numberOfLinks
+ ". link file number of links = " + linkFileList.size() );
}
int from;
int to;
String[] fromNodeInfo;
String[] toNodeInfo;
String[] edgeInfo;
DNVEdge edge;
DNVNode fromNode;
DNVNode toNode;
int lineIndex = 0;
line = graphFileReader.readLine();
while( line != null && !line.equals( "" ) )
{
lineTokenizer = new StringTokenizer( line );
from = Integer.parseInt( lineTokenizer.nextToken() );
to = Integer.parseInt( lineTokenizer.nextToken() );
fromNodeInfo = (String[])nodeFileList.get( from - 1 );
fromNode = (DNVNode)graph.getNodeByBbId( fromNodeInfo[1] );
if( fromNode == null )
{
fromNode = new DNVNode( graph );
fromNode.setLabel( fromNodeInfo[0] );
fromNode.setBbId( fromNodeInfo[1] );
fromNode.setPosition( (float)Math.random(), (float)Math.random() );
graph.addNode( 0, fromNode );
}
toNodeInfo = (String[])nodeFileList.get( to - 1 );
toNode = (DNVNode)graph.getNodeByBbId( toNodeInfo[1] );
if( toNode == null )
{
toNode = new DNVNode( graph );
toNode.setLabel( toNodeInfo[0] );
toNode.setBbId( toNodeInfo[1] );
toNode.setPosition( (float)Math.random(), (float)Math.random() );
graph.addNode( 0, toNode );
}
edgeInfo = (String[])linkFileList.get( lineIndex );
edge = new DNVEdge( fromNode, toNode, graph );
edge.setLabel( edgeInfo[1] + ", " + edgeInfo[3] + ", " + edgeInfo[5] + ", " + edgeInfo[6] + ", " + edgeInfo[7] );
graph.addNode( 0, edge );
line = graphFileReader.readLine();
lineIndex++;
}
graph.writeGraph( dnvFileName );
}
else
{
System.out.println( "WARNING: graph file has no data" );
}