JavaDoc CSVTools

This commit is contained in:
MAMBILA TETE jean philipp 2024-03-18 18:05:47 +01:00
parent a70ac82141
commit 6f4af5c428
3 changed files with 21 additions and 0 deletions

View file

@ -45,11 +45,19 @@ public final class NetworkFormat {
// Tool class // Tool class
} }
/** Convert a {@link java.lang.String} into a {@link java.time.Duration}
* @param duration the {@link java.lang.String}
* @return the {@link java.time.Duration} object
*/
public static Duration parseDuration(String duration) { public static Duration parseDuration(String duration) {
LocalTime time = LocalTime.parse("00:" + duration, DURATION_FORMATTER); LocalTime time = LocalTime.parse("00:" + duration, DURATION_FORMATTER);
return Duration.between(time, ZERO); return Duration.between(time, ZERO);
} }
/** Format a {@link java.time.Duration} into a {@link java.lang.String}
* @param duration an object of type {@link java.time.Duration}
* @return a String that depicts the duration in format MM:SS
*/
public static String formatDuration(Duration duration) { public static String formatDuration(Duration duration) {
return DURATION_INDIVIDUAL_FORMATTER.format(duration.toMinutes()) + ":" return DURATION_INDIVIDUAL_FORMATTER.format(duration.toMinutes()) + ":"
+ DURATION_INDIVIDUAL_FORMATTER.format(duration.toSecondsPart()); + DURATION_INDIVIDUAL_FORMATTER.format(duration.toSecondsPart());

View file

@ -41,6 +41,9 @@ public final class ScheduleFormat {
} }
/** Create a {@link java.time.format.DateTimeFormatter} object used to format Dates
* @return the formatter
*/
public static DateTimeFormatter getTimeFormatter() { public static DateTimeFormatter getTimeFormatter() {
return DateTimeFormatter.ofPattern("HH:mm").withResolverStyle(ResolverStyle.LENIENT); return DateTimeFormatter.ofPattern("HH:mm").withResolverStyle(ResolverStyle.LENIENT);
} }

View file

@ -32,6 +32,11 @@ public final class CSVTools {
// Tool class // Tool class
} }
/** get a CSV file from a URL, download and parse it, and keep values in memory
* @param url the address of the CSV file
* @param contentLineConsumer the variable used to store the data
* @throws IOException if it's impossible to download the file
*/
public static void readCSVFromURL(String url, Consumer<String[]> contentLineConsumer) public static void readCSVFromURL(String url, Consumer<String[]> contentLineConsumer)
throws IOException { throws IOException {
ICSVParser parser = new CSVParserBuilder().withSeparator(';').build(); ICSVParser parser = new CSVParserBuilder().withSeparator(';').build();
@ -52,6 +57,11 @@ public final class CSVTools {
} }
} }
/** 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, public static void writeCSVToFile(String filename,
Stream<String[]> contentLineConsumer) throws IOException { Stream<String[]> contentLineConsumer) throws IOException {
try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) { try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) {