Skip to content

Commit

Permalink
Merge pull request #25 from mdaubie/feat/21/add-formats-enum
Browse files Browse the repository at this point in the history
Feat/21/add formats enum
  • Loading branch information
Matthieu Daubié committed May 4, 2023
2 parents 3d59093 + 81a1024 commit e079e33
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.mdaubie.subtitlesparser.constants;

import io.github.mdaubie.subtitlesparser.model.Format;
import io.github.mdaubie.subtitlesparser.model.SubRipFile;

public final class SUB_FILE_FORMATS {
public static final Format<SubRipFile> SUB_RIP_FORMAT = new Format<>("SubRip", "srt", SubRipFile.class, TIMESTAMP_FORMATS.ISO_8601_COMA.value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.mdaubie.subtitlesparser.constants;

import java.time.format.DateTimeFormatter;

public enum TIMESTAMP_FORMATS {
ISO_8601_COMA(DateTimeFormatter.ofPattern("HH:mm:ss,SSS")),
ISO_8601_DOT(DateTimeFormatter.ofPattern("HH:mm:ss.SSS")),
;

public final DateTimeFormatter value;

TIMESTAMP_FORMATS(DateTimeFormatter value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package io.github.mdaubie.subtitlesparser.model;

import io.github.mdaubie.subtitlesparser.constants.TIMESTAMP_FORMATS;

import java.time.format.DateTimeFormatter;

public record Format<SF extends SubtitlesFile>(String name, String extension,
Class<SF> baseClass,
DateTimeFormatter timestampsFormat) {

public Format(String name, String extension, Class<SF> baseClass, TIMESTAMP_FORMATS timestampsFormat) {
this(name, extension, baseClass, timestampsFormat.value);
}

@Override
public String toString() {
return String.format("Format %s (.%s)", name, extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import org.junit.jupiter.params.provider.MethodSource;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.stream.Stream;

import static io.github.mdaubie.subtitlesparser.constants.SUB_FILE_FORMATS.*;


class ParserTest {
@ParameterizedTest
Expand Down Expand Up @@ -47,9 +48,8 @@ public static Stream<Arguments> parse() {
LocalTime.of(0, 0, 58, 266 * 1000000),
"(FOOTSTEPS THUDDING)"));
}};
Format<SubRipFile> subRipFormat = new Format<>("SubRip", ".srt", SubRipFile.class, DateTimeFormatter.ofPattern("HH:mm:ss,SSS"));
return Stream.of(
Arguments.of(fileContent, subRipFormat, sf)
Arguments.of(fileContent, SUB_RIP_FORMAT, sf)
);
}

Expand Down

0 comments on commit e079e33

Please sign in to comment.