From 201ea8b46452606778b0c7f823f0316626d65ef5 Mon Sep 17 00:00:00 2001 From: Romuald Rousseau Date: Mon, 25 Nov 2024 14:41:48 +0800 Subject: [PATCH] fix: Fix assertions and max retry (#59) Co-authored-by: Romuald Rousseau --- .../python/PythonSimpleDateFormat.java | 137 +++++++++--------- .../src/main/resources/models/.gitkeep | 0 .../archery/parser/LayexTableParser.java | 3 +- .../archery/classifier/NetTagClassifier.java | 2 +- 4 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 archery-examples/src/main/resources/models/.gitkeep diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/python/PythonSimpleDateFormat.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/python/PythonSimpleDateFormat.java index 2544d241..6bc0e1a3 100644 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/python/PythonSimpleDateFormat.java +++ b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/python/PythonSimpleDateFormat.java @@ -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"); } } diff --git a/archery-examples/src/main/resources/models/.gitkeep b/archery-examples/src/main/resources/models/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/archery-layex-parser/src/main/java/com/github/romualdrousseau/archery/parser/LayexTableParser.java b/archery-layex-parser/src/main/java/com/github/romualdrousseau/archery/parser/LayexTableParser.java index 6408beba..50f81d76 100644 --- a/archery-layex-parser/src/main/java/com/github/romualdrousseau/archery/parser/LayexTableParser.java +++ b/archery-layex-parser/src/main/java/com/github/romualdrousseau/archery/parser/LayexTableParser.java @@ -86,7 +86,8 @@ public List getDataTables(final BaseSheet sheet, final Listget("model").isPresent() : "model element must exist"; + assert !this.isModelTemp || this.isModelTemp && model.getData().get("model").isPresent() : "model element must exist"; this.setModel(model); this.setTagStyle(tagStyle);