From c8afbdc2c66884188ac62d69c8df2d0b3541985f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20N=C3=B3brega?= Date: Tue, 3 Feb 2026 10:59:42 -0300 Subject: [PATCH 1/4] refactor: using delimiter values instead of hardcoded chars --- src/main/java/dev/toonformat/jtoon/Delimiter.java | 14 +++++++++----- .../dev/toonformat/jtoon/decoder/DecodeHelper.java | 4 +++- .../jtoon/decoder/TabularArrayDecoder.java | 7 ++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/toonformat/jtoon/Delimiter.java b/src/main/java/dev/toonformat/jtoon/Delimiter.java index 442cec1..3e49fb7 100644 --- a/src/main/java/dev/toonformat/jtoon/Delimiter.java +++ b/src/main/java/dev/toonformat/jtoon/Delimiter.java @@ -7,21 +7,21 @@ public enum Delimiter { /** * Comma delimiter (,) - default option */ - COMMA(","), + COMMA(','), /** * Tab delimiter (\t) */ - TAB("\t"), + TAB('\t'), /** * Pipe delimiter (|) */ - PIPE("|"); + PIPE('|'); - private final String value; + private char value; - Delimiter(String value) { + Delimiter(char value) { this.value = value; } @@ -31,6 +31,10 @@ public enum Delimiter { */ @Override public String toString() { + return String.valueOf(value); + } + + public char getValue() { return value; } } diff --git a/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java b/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java index 75c6c99..2eaf392 100644 --- a/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java +++ b/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java @@ -1,5 +1,7 @@ package dev.toonformat.jtoon.decoder; +import dev.toonformat.jtoon.Delimiter; + import java.util.List; import java.util.Map; @@ -47,7 +49,7 @@ private static int computeLeadingSpaces(String line, DecodeContext context) { char c = line.charAt(i); if (c == ' ') { leadingSpaces++; - } else if (c == '\t') { + } else if (c == Delimiter.TAB.getValue()) { if (context.options.strict()) { throw new IllegalArgumentException( "Tab character used in indentation at line " + (context.currentLine + 1)); diff --git a/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java b/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java index e4aeece..1feaeb6 100644 --- a/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java +++ b/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java @@ -118,15 +118,16 @@ private static void validateKeysDelimiter(String keysStr, Delimiter expectedDeli * @param actualChar the actual delimiter character */ private static void checkDelimiterMismatch(char expectedChar, char actualChar) { - if (expectedChar == '\t' && actualChar == ',') { + if (expectedChar == Delimiter.TAB.getValue() && actualChar == Delimiter.COMMA.getValue()) { throw new IllegalArgumentException( "Delimiter mismatch: bracket declares tab, brace fields use comma"); } - if (expectedChar == '|' && actualChar == ',') { + if (expectedChar == Delimiter.PIPE.getValue() && actualChar == Delimiter.COMMA.getValue()) { throw new IllegalArgumentException( "Delimiter mismatch: bracket declares pipe, brace fields use comma"); } - if (expectedChar == ',' && (actualChar == '\t' || actualChar == '|')) { + if (expectedChar == Delimiter.COMMA.getValue() && + (actualChar == Delimiter.TAB.getValue() || actualChar == Delimiter.PIPE.getValue())) { throw new IllegalArgumentException( "Delimiter mismatch: bracket declares comma, brace fields use different delimiter"); } From 0fa2cc6d0ece36b67aee5d752d3e567c6e44e6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20N=C3=B3brega?= Date: Tue, 3 Feb 2026 11:00:22 -0300 Subject: [PATCH 2/4] turning value to final --- src/main/java/dev/toonformat/jtoon/Delimiter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/toonformat/jtoon/Delimiter.java b/src/main/java/dev/toonformat/jtoon/Delimiter.java index 3e49fb7..033a078 100644 --- a/src/main/java/dev/toonformat/jtoon/Delimiter.java +++ b/src/main/java/dev/toonformat/jtoon/Delimiter.java @@ -19,7 +19,7 @@ public enum Delimiter { */ PIPE('|'); - private char value; + private final char value; Delimiter(char value) { this.value = value; From a83afe3b17db9f0913649f55a9e95beaf2320515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20N=C3=B3brega?= Date: Tue, 3 Feb 2026 11:25:28 -0300 Subject: [PATCH 3/4] using string for value instead of char --- src/main/java/dev/toonformat/jtoon/Delimiter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/dev/toonformat/jtoon/Delimiter.java b/src/main/java/dev/toonformat/jtoon/Delimiter.java index 033a078..4e5ebe0 100644 --- a/src/main/java/dev/toonformat/jtoon/Delimiter.java +++ b/src/main/java/dev/toonformat/jtoon/Delimiter.java @@ -7,21 +7,21 @@ public enum Delimiter { /** * Comma delimiter (,) - default option */ - COMMA(','), + COMMA(","), /** * Tab delimiter (\t) */ - TAB('\t'), + TAB("\t"), /** * Pipe delimiter (|) */ - PIPE('|'); + PIPE("|"); - private final char value; + private final String value; - Delimiter(char value) { + Delimiter(String value) { this.value = value; } @@ -31,10 +31,10 @@ public enum Delimiter { */ @Override public String toString() { - return String.valueOf(value); + return value; } public char getValue() { - return value; + return value.charAt(0); } } From 2ec9787c7865e60d13b61eb48acd6df592658b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20N=C3=B3brega?= Date: Tue, 3 Feb 2026 11:32:31 -0300 Subject: [PATCH 4/4] removing hardcoded values referent to Delimiter in tests --- .../dev/toonformat/jtoon/decoder/ArrayDecoderTest.java | 2 +- .../toonformat/jtoon/decoder/TabularArrayDecoderTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java b/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java index 353385e..197ec25 100644 --- a/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java +++ b/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java @@ -120,7 +120,7 @@ void expectsToExtractSlashFromDelimiter() { Delimiter result = ArrayDecoder.extractDelimiterFromHeader("[3|]", context); // Then - assertEquals("|", result.toString()); + assertEquals(Delimiter.PIPE.toString(), result.toString()); } @Test diff --git a/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java b/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java index e31ca49..7c737ee 100644 --- a/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java +++ b/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java @@ -172,8 +172,8 @@ void validateKeysDelimiter() throws Exception { @DisplayName("validateKeysDelimiter get called and branches will be checked") void checkDelimiterMismatchExecution() { // Given - String expectedChar = "|"; - String actualChar = ","; + String expectedChar = Delimiter.PIPE.toString(); + String actualChar = Delimiter.COMMA.toString(); // When InvocationTargetException exception = assertThrows(InvocationTargetException.class, @@ -187,8 +187,8 @@ void checkDelimiterMismatchExecution() { @DisplayName("validateKeysDelimiter get called and branches will be checked") void checkDelimiterMismatchExecutionWithComa() { // Given - String expectedChar = ","; - String actualChar = "|"; + String expectedChar = Delimiter.COMMA.toString(); + String actualChar = Delimiter.PIPE.toString(); // When InvocationTargetException exception = assertThrows(InvocationTargetException.class,