From 06d80926e06d6908712c833ca6ac8556b27efd16 Mon Sep 17 00:00:00 2001 From: AngeHerman Date: Mon, 8 Apr 2024 14:18:18 +0200 Subject: [PATCH] Bugs resolved --- .../project/idfm/CSVSchedulesProvider.java | 6 ++- .../gla/project/idfm/CSVStreamProvider.java | 37 +++++++++++-------- .../u_paris/gla/project/utils/CSVTools.java | 19 +++++++++- .../project/idfm/CSVStreamProviderTest.java | 10 ++--- .../idfm/IDFMNetworkExtractorTest.java | 2 +- .../gla/project/idfm/TraceEntryTest.java | 6 +-- 6 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java index 9f5f907..52835d3 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java @@ -105,12 +105,14 @@ public class CSVSchedulesProvider { } } - public String[][] next() { + public String[] next() { if (!hasNext()) { return null; } skipToNext(); - return new String[][]{Arrays.copyOf(this.line, this.line.length)}; + return Arrays.copyOf(this.line, this.line.length); + + // return new String[][]{Arrays.copyOf(this.line, this.line.length)}; } diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java index 3a48c1a..0249eac 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java @@ -130,7 +130,7 @@ public final class CSVStreamProvider { } while (currentSegmentStart == null); } - public String[][] next() { + public String[] next() { if (!this.onNext) { skipToNext(); } @@ -148,7 +148,9 @@ public final class CSVStreamProvider { this.line[NetworkFormat.VARIANT_INDEX] = Integer .toString(bifurcation); fillTransports(bifurcation); - return new String[][]{Arrays.copyOf(this.line, this.line.length)}; + return Arrays.copyOf(this.line, this.line.length); + // return new String[][]{Arrays.copyOf(this.line, this.line.length)}; + } /** @param stop1 @@ -182,21 +184,24 @@ public final class CSVStreamProvider { } private void fillTransports(int bif) { - String nameTransport = this.line[NetworkFormat.LINE_INDEX]; - String start_p = this.line[NetworkFormat.START_INDEX]; - String end_p = this.line[NetworkFormat.STOP_INDEX]; - // String bifurcation = this.line[NetworkFormat.VARIANT_INDEX]; - Transport transp = null; - if(!transports.containsKey(traceId)){ - transp = new Transport(nameTransport,traceType); - transports.put(traceId, transp); - }else{ - transp = transports.get(traceId); - } - transp.addStop(start_p, end_p, bif); - if(transp.descriptions.isEmpty()){ - transp.addDescriptions(descriptions); + if(transports != null){ + String nameTransport = this.line[NetworkFormat.LINE_INDEX]; + String start_p = this.line[NetworkFormat.START_INDEX]; + String end_p = this.line[NetworkFormat.STOP_INDEX]; + // String bifurcation = this.line[NetworkFormat.VARIANT_INDEX]; + Transport transp = null; + if(!transports.containsKey(traceId)){ + transp = new Transport(nameTransport,traceType); + transports.put(traceId, transp); + }else{ + transp = transports.get(traceId); + } + transp.addStop(start_p, end_p, bif); + if(transp.descriptions.isEmpty()){ + transp.addDescriptions(descriptions); + } } + } diff --git a/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java b/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java index 9886b4d..b511757 100644 --- a/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java +++ b/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java @@ -69,13 +69,28 @@ public final class CSVTools { * @throws IOException if we can't write the data into the file */ public static void writeCSVToFile(String filename, - Stream contentLinesConsumer) throws IOException { + Stream contentLinesConsumer) throws IOException { try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) { CSVWriterBuilder wBuilder = new CSVWriterBuilder(writer).withSeparator(';'); try (ICSVWriter csv = wBuilder.build()) { - contentLinesConsumer.forEachOrdered(line -> Arrays.stream(line).forEach(csv::writeNext)); + contentLinesConsumer.forEachOrdered(csv::writeNext); } } } + // /** Save our current CSV variable's data into an actual file + // * @param filename the saved file's name and path + // * @param contentLineConsumer our data variable + // * @throws IOException if we can't write the data into the file + // */ + // public static void writeCSVToFile(String filename, + // Stream contentLinesConsumer) throws IOException { + // try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) { + // CSVWriterBuilder wBuilder = new CSVWriterBuilder(writer).withSeparator(';'); + // try (ICSVWriter csv = wBuilder.build()) { + // contentLinesConsumer.forEachOrdered(line -> Arrays.stream(line).forEach(csv::writeNext)); + // } + // } + // } + } diff --git a/src/test/java/fr/u_paris/gla/project/idfm/CSVStreamProviderTest.java b/src/test/java/fr/u_paris/gla/project/idfm/CSVStreamProviderTest.java index 2c7c7fa..a9994b5 100644 --- a/src/test/java/fr/u_paris/gla/project/idfm/CSVStreamProviderTest.java +++ b/src/test/java/fr/u_paris/gla/project/idfm/CSVStreamProviderTest.java @@ -21,7 +21,7 @@ public class CSVStreamProviderTest { @Test public void testHasNext() { // Scénario sans Trace - CSVStreamProvider providerWithoutTrace = new CSVStreamProvider(Collections.emptyIterator()); + CSVStreamProvider providerWithoutTrace = new CSVStreamProvider(Collections.emptyIterator(),null); assertFalse(providerWithoutTrace.hasNext(), "hasNext should return false when no traces are provided"); // Scénario avec Trace @@ -29,10 +29,10 @@ public class CSVStreamProviderTest { StopEntry stop2 = new StopEntry("Stop2", 2.295, 48.8738); List path = Arrays.asList(stop1, stop2); - TraceEntry trace = new TraceEntry("Ligne1"); + TraceEntry trace = new TraceEntry("Ligne1","IDFM:03434","Bus"); trace.addPath(path); - CSVStreamProvider providerWithTrace = new CSVStreamProvider(Arrays.asList(trace).iterator()); + CSVStreamProvider providerWithTrace = new CSVStreamProvider(Arrays.asList(trace).iterator(),null); assertTrue(providerWithTrace.hasNext(), "hasNext should return true when traces are provided"); } @@ -45,10 +45,10 @@ public class CSVStreamProviderTest { StopEntry start = new StopEntry("Début", 2.3522, 48.8566); // Paris StopEntry end = new StopEntry("Fin", 2.295, 48.8738); // Proche de Paris - TraceEntry traceEntry = new TraceEntry("Ligne1"); + TraceEntry traceEntry = new TraceEntry("Ligne1","IDFM:03434","Bus"); traceEntry.addPath(Arrays.asList(start, end)); // Ajout d'un chemin à la trace - CSVStreamProvider provider = new CSVStreamProvider(Collections.singletonList(traceEntry).iterator()); + CSVStreamProvider provider = new CSVStreamProvider(Collections.singletonList(traceEntry).iterator(),null); assertTrue(provider.hasNext(), "Doit avoir un prochain élément"); diff --git a/src/test/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractorTest.java b/src/test/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractorTest.java index 35c1d3e..c4bbb12 100644 --- a/src/test/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractorTest.java +++ b/src/test/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractorTest.java @@ -43,7 +43,7 @@ class IDFMNetworkExtractorTest { public void testAddCandidate() throws Exception { UnidentifiedStopEntry unidentifiedStop = new UnidentifiedStopEntry(2.3522, 48.8566); // Coordonnées pour Paris List path = new ArrayList<>(Arrays.asList(unidentifiedStop)); - TraceEntry trace = new TraceEntry("Ligne1"); + TraceEntry trace = new TraceEntry("Ligne1","IDFM:03434","Bus"); trace.addPath(path); StopEntry candidate = new StopEntry("Proche Candidat", 2.3523, 48.8567); // Coordonnées proches diff --git a/src/test/java/fr/u_paris/gla/project/idfm/TraceEntryTest.java b/src/test/java/fr/u_paris/gla/project/idfm/TraceEntryTest.java index 6ba7bdb..935b89d 100644 --- a/src/test/java/fr/u_paris/gla/project/idfm/TraceEntryTest.java +++ b/src/test/java/fr/u_paris/gla/project/idfm/TraceEntryTest.java @@ -9,7 +9,7 @@ public class TraceEntryTest { //addTerminus @Test public void testAddTerminus() { - TraceEntry traceEntry = new TraceEntry("Ligne 1"); + TraceEntry traceEntry = new TraceEntry("Ligne 1","IDFM:03434","Bus"); String terminus1 = "Terminus A"; String terminus2 = "Terminus B"; @@ -26,7 +26,7 @@ public class TraceEntryTest { //addPath @Test public void testAddPath() { - TraceEntry traceEntry = new TraceEntry("Ligne 1"); + TraceEntry traceEntry = new TraceEntry("Ligne 1","IDFM:03434","Bus"); StopEntry stop1 = new StopEntry("Station 1", 2.300, 48.850); StopEntry stop2 = new StopEntry("Station 2", 2.310, 48.855); List path = Arrays.asList(stop1, stop2); @@ -42,7 +42,7 @@ public class TraceEntryTest { //Verfier si le nom de la ligne lname est correctement initialiser @Test public void testTraceEntryName() { - TraceEntry traceEntry = new TraceEntry("Ligne 1"); + TraceEntry traceEntry = new TraceEntry("Ligne 1","IDFM:03434","Bus"); assertEquals("Ligne 1", traceEntry.lname, "Le nom de la ligne doit être 'Ligne 1'."); } } \ No newline at end of file