Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix assertions and max retry #59

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,90 +1,95 @@
package com.github.romualdrousseau.archery.commons.python;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class PythonSimpleDateFormat extends SimpleDateFormat {

private final String pythonPattern;
private final Locale locale;

public PythonSimpleDateFormat() {
this("", Locale.US);
public PythonSimpleDateFormat(final String pythonPattern) {
this(pythonPattern, Locale.getDefault());
}

public PythonSimpleDateFormat(final String pattern) {
this(pattern, PythonSimpleDateFormat.toJavaLocale(pattern));
}

public PythonSimpleDateFormat(final String pattern, Locale locale) {
super(PythonSimpleDateFormat.toJava(pattern), locale);
public PythonSimpleDateFormat(final String pythonPattern, Locale locale) {
super(PythonSimpleDateFormat.toJavaPattern(pythonPattern), locale);
this.pythonPattern = pythonPattern;
this.locale = locale;
}

public static String toPython(final String javaPattern) {
return javaPattern
.replaceAll("YYYY", "%G")
.replaceAll("yyyy", "%Y")
.replaceAll("yy", "%y")
.replaceAll("y", "%-y")
.replaceAll("MMMMM", "%B")
.replaceAll("MMM", "%b")
.replaceAll("MM", "%m")
.replaceAll("M", "%-m")
.replaceAll("DDD", "%j")
.replaceAll("dd", "%d")
.replaceAll("d", "%-d")
.replaceAll("EEEEE", "%A")
.replaceAll("EEE", "%a")
.replaceAll("ww", "%W")
.replaceAll("u", "%u")
.replaceAll("HH", "%H")
.replaceAll("H", "%-H")
.replaceAll("hh", "%I")
.replaceAll("h", "%-I")
.replaceAll("mm", "%M")
.replaceAll("m", "%-M")
.replaceAll("ss", "%S")
.replaceAll("s", "%-S");
public String getPythonPattern() {
return this.pythonPattern;
}

public static String toJava(final String pythonPattern) {
return pythonPattern
.replaceAll("%G", "YYYY")
.replaceAll("%Y", "yyyy")
.replaceAll("%y", "yy")
.replaceAll("%-y", "y")
.replaceAll("%B", "MMMMM")
.replaceAll("%b", "MMM")
.replaceAll("%m", "MM")
.replaceAll("%-m", "M")
.replaceAll("%j", "DDD")
.replaceAll("%d", "dd")
.replaceAll("%-d", "d")
.replaceAll("%A", "EEEEE")
.replaceAll("%a", "EEE")
.replaceAll("%W", "ww")
.replaceAll("%w", "u")
.replaceAll("%u", "u")
.replaceAll("%U", "ww")
.replaceAll("%H", "HH")
.replaceAll("%-H", "H")
.replaceAll("%I", "hh")
.replaceAll("%-I", "h")
.replaceAll("%M", "mm")
.replaceAll("%-M", "m")
.replaceAll("%S", "ss")
.replaceAll("%-S", "s");
public Locale getLocale() {
return this.locale;
}

public static Locale toJavaLocale(final String pythonPattern) {
if (pythonPattern.contains("%w") || pythonPattern.contains("%W")) {
return Locale.UK;
public int getFirstDayOfWeek() {
if (this.pythonPattern.contains("%w") || this.pythonPattern.contains("%W")) {
return Calendar.MONDAY;
} else if (this.pythonPattern.contains("%u") || this.pythonPattern.contains("%U")) {
return Calendar.SUNDAY;
} else {
return Locale.US;
return -1;
}
}

public Locale getLocale() {
return this.locale;
public static String toPythonPattern(final String javaPattern) {
return javaPattern
.replaceAll("YYYY", "%G")
.replaceAll("yyyy", "%Y")
.replaceAll("yy", "%y")
.replaceAll("y", "%-y")
.replaceAll("MMMMM", "%B")
.replaceAll("MMM", "%b")
.replaceAll("MM", "%m")
.replaceAll("M", "%-m")
.replaceAll("DDD", "%j")
.replaceAll("dd", "%d")
.replaceAll("d", "%-d")
.replaceAll("EEEEE", "%A")
.replaceAll("EEE", "%a")
.replaceAll("ww", "%W")
.replaceAll("u", "%u")
.replaceAll("HH", "%H")
.replaceAll("H", "%-H")
.replaceAll("hh", "%I")
.replaceAll("h", "%-I")
.replaceAll("mm", "%M")
.replaceAll("m", "%-M")
.replaceAll("ss", "%S")
.replaceAll("s", "%-S");
}

public static String toJavaPattern(final String pythonPattern) {
return pythonPattern
.replaceAll("%G", "YYYY")
.replaceAll("%Y", "yyyy")
.replaceAll("%y", "yy")
.replaceAll("%-y", "y")
.replaceAll("%B", "MMMMM")
.replaceAll("%b", "MMM")
.replaceAll("%m", "MM")
.replaceAll("%-m", "M")
.replaceAll("%j", "DDD")
.replaceAll("%d", "dd")
.replaceAll("%-d", "d")
.replaceAll("%A", "EEEEE")
.replaceAll("%a", "EEE")
.replaceAll("%W", "ww")
.replaceAll("%w", "u")
.replaceAll("%u", "u")
.replaceAll("%U", "ww")
.replaceAll("%H", "HH")
.replaceAll("%-H", "H")
.replaceAll("%I", "hh")
.replaceAll("%-I", "h")
.replaceAll("%M", "mm")
.replaceAll("%-M", "m")
.replaceAll("%S", "ss")
.replaceAll("%-S", "s");
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public List<DataTable> getDataTables(final BaseSheet sheet, final List<BaseTable
final var table = remainingTables.pollFirst();
table.setVisited(false);

for (var rowOffset = 0; rowOffset < TRY_LAYEX_COUNT; rowOffset++) {
final var maxRowOffset = Math.min(TRY_LAYEX_COUNT, table.getLastRow() - table.getFirstRow());
for (var rowOffset = 0; rowOffset < maxRowOffset; rowOffset++) {
final var lexer = new TableLexer(table, rowOffset);
for (final var matcher : matchers) {
if (!table.isVisited()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public NetTagClassifier(final Model model, final TagClassifier.TagStyle tagStyle
model.getData().getList("lexicon"),
Optional.ofNullable(model.getModelAttributes().get("modelPath")).map(Path::of));

assert this.isModelTemp && model.getData().<String>get("model").isPresent() : "model element must exist";
assert !this.isModelTemp || this.isModelTemp && model.getData().<String>get("model").isPresent() : "model element must exist";

this.setModel(model);
this.setTagStyle(tagStyle);
Expand Down
Loading