From a98ceaa4f83410be61c72b6e8252a985515a12d9 Mon Sep 17 00:00:00 2001 From: Bigeon Emmanuel Date: Wed, 14 Feb 2024 11:21:51 +0100 Subject: [PATCH] [feat] client format specs --- pom.xml | 5 ++ .../u_paris/gla/project/io/NetworkFormat.java | 66 +++++++++++++++++++ .../gla/project/io/ScheduleFormat.java | 37 +++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java create mode 100644 src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java diff --git a/pom.xml b/pom.xml index edbf89e..a2107ad 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,11 @@ junit-jupiter 5.9.1 + + com.opencsv + opencsv + 5.4 + diff --git a/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java b/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java new file mode 100644 index 0000000..ff95c99 --- /dev/null +++ b/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java @@ -0,0 +1,66 @@ +/** + * + */ +package fr.u_paris.gla.project.io; + +import java.text.NumberFormat; +import java.time.Duration; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.Temporal; +import java.util.Locale; + +/** Definition of the formats of files for this project. + * + * @author Emmanuel Bigeon */ +public final class NetworkFormat { + + public static final int NUMBER_COLUMNS = 8; + public static final int GPS_PRECISION = 18; + + /** The index of the line name in the network format */ + public static final int LINE_INDEX = 0; + /** The index of the variant number of the segment in the network format */ + public static final int VARIANT_INDEX = 1; + /** The index of the segment trip duration in the network format */ + public static final int DURATION_INDEX = 6; + /** The index of the segment distance in the network format */ + public static final int DISTANCE_INDEX = 7; + /** The index of the segment end stop name in the network format */ + public static final int STOP_INDEX = 4; + /** The index of the segment starting stop name in the network format */ + public static final int START_INDEX = 2; + + private static final DateTimeFormatter DURATION_FORMATTER = DateTimeFormatter + .ofPattern("HH:mm:ss"); + private static final NumberFormat DURATION_SECONDS_FORMATTER = NumberFormat + .getIntegerInstance(Locale.ENGLISH); + static { + DURATION_SECONDS_FORMATTER.setMinimumIntegerDigits(2); + } + private static final Temporal ZERO = LocalTime.parse("00:00:00"); + + /** Hidden constructor for utility class */ + private NetworkFormat() { + // Tool class + } + + public static Duration parseDuration(String duration) { + LocalTime time = LocalTime.parse("00:" + duration, DURATION_FORMATTER); + return Duration.between(time, ZERO); + } + + public static String formatDuration(Duration duration) { + return Long.toString(duration.toMinutes()) + ":" + + DURATION_SECONDS_FORMATTER.format(duration.toSecondsPart()); + } + + /** Get a formatter for the numbers in a GPS coordinate pair + * + * @return the formatter for numbers in a GPS coordinate pair */ + public static NumberFormat getGPSFormatter() { + NumberFormat instance = NumberFormat.getNumberInstance(Locale.ENGLISH); + instance.setMaximumFractionDigits(GPS_PRECISION); + return instance; + } +} diff --git a/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java b/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java new file mode 100644 index 0000000..ba4a645 --- /dev/null +++ b/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java @@ -0,0 +1,37 @@ +/** + * + */ +package fr.u_paris.gla.project.io; + +import java.time.format.DateTimeFormatter; +import java.time.format.ResolverStyle; +import java.util.List; + +/** A tool class for the schedule format. + * + * @author Emmanuel Bigeon */ +public final class ScheduleFormat { + public static final int LINE_INDEX = 0; + public static final int TRIP_SEQUENCE_INDEX = 1; + public static final int TERMINUS_INDEX = 2; + public static final int TIME_INDEX = 3; + + /** Hidden constructor for tool class */ + private ScheduleFormat() { + // Tool class + } + + /** Read a trip sequence from its string representation + * + * @param representation the representation + * @return the sequence of branching */ + public static List getTripSequence(String representation) { + // TODO Read a trip sequence from a string + + throw new RuntimeException("Not implemented yet"); + } + + public static DateTimeFormatter getTimeFormatter() { + return DateTimeFormatter.ofPattern("HH:mm").withResolverStyle(ResolverStyle.LENIENT); + } +}