From 92382857d2d90b21c7742369f46848e76d43bbf0 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 8 Apr 2024 14:19:44 +0200 Subject: [PATCH] JavaDoc for the graph creation --- pom.xml | 2 +- .../gla/project/itinerary/Connection.java | 2 ++ .../u_paris/gla/project/itinerary/Graph.java | 1 - .../{Main.java => ItineraryCalculator.java} | 31 ++++++++++++------- .../u_paris/gla/project/itinerary/Stop.java | 2 ++ 5 files changed, 25 insertions(+), 13 deletions(-) rename src/main/java/fr/u_paris/gla/project/itinerary/{Main.java => ItineraryCalculator.java} (83%) diff --git a/pom.xml b/pom.xml index 89cd54d..61d26c4 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ true ${project.build.finalName}.lib/ - fr.u_paris.gla.project.itinerary.Main + fr.u_paris.gla.project.itinerary.ItineraryCalculator diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Connection.java b/src/main/java/fr/u_paris/gla/project/itinerary/Connection.java index ccc3bfd..1cafbec 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Connection.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Connection.java @@ -1,8 +1,10 @@ package fr.u_paris.gla.project.itinerary; public class Connection{ + // Destination of the connection between the two stops private final Stop stop; + // The line used for this connection private final String lineName; private final double distance; diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java b/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java index 3025a04..795add9 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java @@ -22,7 +22,6 @@ public class Graph{ return nodes; } - public Map> getConnections() { return connections; } diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Main.java b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java similarity index 83% rename from src/main/java/fr/u_paris/gla/project/itinerary/Main.java rename to src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java index 5a75b34..5391c19 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Main.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java @@ -9,7 +9,7 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; -public class Main{ +public class ItineraryCalculator { private static final Logger LOGGER = Logger .getLogger(IDFMNetworkExtractor.class.getName()); @@ -36,9 +36,8 @@ public class Main{ private static final int IDFM_TRACE_DISTANCE_INDEX = 7; - private static final double MARGE_ERREUR = 1.; + private static final double ERROR_MARGIN = 1.; - // Parser helper values /** * Returns the coordinates from a String to a double array: @@ -51,13 +50,23 @@ public class Main{ return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])}; } + /** + * Searchs for a stop with the same name and GPS coordinates in the graph, and creates it if non existant + * @param nodes a graph of the stops + * @param tmp list of the created stops + * @param name the name of the stop + * @param gps the coordinate of the stop + * @param lineId the line the stop is on + * @return the Stop object + */ private static Stop getOrCreateStop(HashSet nodes, HashMap> tmp, String name, String gps, String lineId) { ArrayList stopList = tmp.get(name); + // First we search by name, and then compare the coordinates since multiple stations can have the same name. A margin of error is necessary since stops can have multiple GPS coordinates if (stopList != null) { for(Stop stop : stopList) { double[] coords = getCoords(gps); double dist = GPS.distance(coords[0], coords[1], stop.getLatitude(), stop.getLongitude()); - if(dist < MARGE_ERREUR) { + if(dist < ERROR_MARGIN) { stop.addLine(lineId); return stop; } @@ -73,8 +82,13 @@ public class Main{ return newStop; } - public static int lineNB = 0; - + /** + * Adds into the graph the connection between two stops, parsed from a CSV line + * @param line the current line we want to parse + * @param nodes the graph of stops + * @param tmp list of the created stops + * @param connections + */ private static void addLine(String[] line, HashSet nodes, HashMap> tmp, HashMap> connections) { Stop fromStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_FROM_INDEX], line[IDFM_TRACE_FROM_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]); Stop toStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]); @@ -87,11 +101,6 @@ public class Main{ connections.computeIfAbsent(fromStop, k -> new HashSet<>()).add(connection); } - public static void find(Graph graph){ - - - } - public static void main(String[] args){ if (args.length != 0) { LOGGER.severe("Invalid command line. Target file names are in the main file for now."); diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java b/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java index 240c9b0..98a2306 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java @@ -4,10 +4,12 @@ import java.util.HashSet; import java.util.Set; public class Stop implements GraphNode { + // The total number of stops private static int counter = 0; private final int id; + // The set of all the lines the stop is on private final Set lines; private final String name;