[feat] client format specs

This commit is contained in:
Bigeon Emmanuel 2024-02-14 11:21:51 +01:00
parent 8334dd1854
commit a98ceaa4f8
3 changed files with 108 additions and 0 deletions

View file

@ -23,6 +23,11 @@
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.4</version>
</dependency>
</dependencies>
<build>

View file

@ -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;
}
}

View file

@ -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<Integer> 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);
}
}