import datastructure.*;
import dijkstra.*;
import io.*;
import java.lang.management.*;

//import org.jgrapht.ListenableGraph;
//import org.jgrapht.graph.ListenableUndirectedGraph;

/** @brief Main class that reads in a file of the specified format and calculates the
 * furthest vertex from vertex 1 and its distance.
 * 
 * Reads a file of the format:
 * nVertices nEdges
 * headId tailId weight
 * headId tailId weight
 *          .
 *          .
 *          .
 * 
 * Prints the result vertex and restult distance
 * @author Merlin Viernickel
 * @date June 08 2017
 */
public class ex5 {
    
    private static final String MYALGORITHM = "0";
    private static final String LIBALGORITHM = "1";
    
    /**
     * Main method
     * @param args String array with algorithm mode (0 or 1) as first entry and path to file as second entry
     */
    public static void main(String[] args){
        long startWallClockTimeNano = System.nanoTime();
        long startUserTimeNano   = getUserTime();
        
        Node[] nodes = Reader.readFile(args[0]);
        
        /** Mode 0: Use custom Dijkstra implementation */
        //if(args[0].equals(MYALGORITHM))
        {
            Dijkstra dijkstra = new Dijkstra(nodes);
            Node furthestNode = dijkstra.findFurthestNode();
            
            long taskWallClockTimeNano  = System.nanoTime() - startWallClockTimeNano;
            long taskUserTimeNano    = getUserTime( ) - startUserTimeNano;
            
            System.out.println("RESULT VERTEX " + (furthestNode.id+1));
            System.out.println("RESULT DIST " + furthestNode.distance);
            
            System.out.println("RESULT WALL-CLOCK TIME: " + (round(taskWallClockTimeNano/1000000000.0)) + " seconds");
            System.out.println("RESULT USER TIME: " + (round(taskUserTimeNano/1000000000.0)) + " seconds");
            
            
        /** Mode 1: Use library Dijkstra implementation
        }else if(args[0].equals(LIBALGORITHM)){

            ListenableGraph<Node, Edge> graph = new ListenableUndirectedGraph<Node, Edge>(Edge.class);
            

            for(int i=0; i<nodes.length; i++){
                graph.addVertex(nodes[i]);
            }
            

            for(int i=0; i<nodes.length; i++){
                Node node = nodes[i];
                for(int j=0; j<node.edges.size(); j++){
                    if(node.edges.get(j).head.equals(node)){
                        graph.addEdge(node, node.edges.get(j).tail, node.edges.get(j));
                    }
                }
            }
        }else{
            System.out.println("Invalid Algorithm Mode.");
            */
        }
    }
    
    /** Round to three decimal places */
    public static double round(double x){
        return Math.round(x*1000)/1000.0;
    }
     
    /** Get user time in nanoseconds. */
    public static long getUserTime(){
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        return bean.isCurrentThreadCpuTimeSupported() ?
            bean.getCurrentThreadUserTime() : 0L;
    }
}

@@ -85,101 +85,8 @@
 *;%0A%0A
-//import org.jgrapht.ListenableGraph;%0A//import org.jgrapht.graph.ListenableUndirectedGraph;%0A%0A
 /** 
@@ -955,13 +955,47 @@
 rgs%5B
-0
+1
 %5D);%0A
+        Node furthestNode = null;%0A
     
@@ -1069,10 +1069,8 @@
     
-//
 if(a
@@ -1176,74 +1176,534 @@
     
-Node furthestNode = dijkstra.findFurthestNode();%0A            %0A    
+furthestNode = dijkstra.findFurthestNode();                   %0A        /** Mode 1: Use library Dijkstra implementation */%0A        %7Delse if(args%5B0%5D.equals(LIBALGORITHM))%7B%0A        %09JGraphTDijkstra dijkstra = new JGraphTDijkstra(nodes);%0A        %09furthestNode = dijkstra.findFurthestNode();%0A        %7Delse%7B%0A            System.out.println(%22Invalid Algorithm Mode.%22);%0A            System.out.println(%22Proper usage: ex5 0 path/to/file/file.txt%22);%0A            return;%0A        %7D%0A        %0A        /** Get Wall-clock time and user time */%0A
     
@@ -1772,36 +1772,32 @@
 lClockTimeNano;%0A
-    
         long tas
@@ -1855,33 +1855,63 @@
 no;%0A        
+%0A
     
-%0A
     
+/** Print results */%0A        %0A
         Syst
@@ -1966,36 +1966,32 @@
 id+1));%0A        
- 
-   
 System.out.print
@@ -2038,33 +2038,25 @@
 e);%0A        
-    %0A    
+%0A
         Syst
@@ -2158,36 +2158,32 @@
 onds%22);%0A        
-    
 System.out.print
@@ -2266,817 +2266,8 @@
 %22);%0A
-            %0A            %0A        /** Mode 1: Use library Dijkstra implementation%0A        %7Delse if(args%5B0%5D.equals(LIBALGORITHM))%7B%0A%0A            ListenableGraph%3CNode, Edge%3E graph = new ListenableUndirectedGraph%3CNode, Edge%3E(Edge.class);%0A            %0A%0A            for(int i=0; i%3Cnodes.length; i++)%7B%0A                graph.addVertex(nodes%5Bi%5D);%0A            %7D%0A            %0A%0A            for(int i=0; i%3Cnodes.length; i++)%7B%0A                Node node = nodes%5Bi%5D;%0A                for(int j=0; j%3Cnode.edges.size(); j++)%7B%0A                    if(node.edges.get(j).head.equals(node))%7B%0A                        graph.addEdge(node, node.edges.get(j).tail, node.edges.get(j));%0A                    %7D%0A                %7D%0A            %7D%0A        %7Delse%7B%0A            System.out.println(%22Invalid Algorithm Mode.%22);%0A            */%0A        %7D%0A
     

Update ex5