Merge branch 'client-format' into idf-mobilite-net

This commit is contained in:
Bigeon Emmanuel 2024-02-14 14:20:46 +01:00
commit 93d0df7759
2 changed files with 103 additions and 0 deletions

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