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

Variable decimal mark without UNA in EDIFACT versions 1-3 #407

Merged
merged 1 commit into from
Dec 7, 2023
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
Expand Up @@ -25,7 +25,7 @@ public abstract class Dialect {
protected char segmentDelimiter;
protected char segmentTagTerminator = '\0';
protected char elementDelimiter;
protected char decimalMark;
protected char decimalMark = '\0';
protected char releaseIndicator;
protected char componentDelimiter;
protected char elementRepeater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class EDIFACTDialect extends Dialect {
StringBuilder header;
private int index = -1;
private int unbStart = -1;
private boolean ignoreDecimalAdvice;
private boolean variableDecimalMark;

private static final int TX_AGENCY = 0;
private static final int TX_VERSION = 1;
Expand All @@ -65,11 +65,11 @@ public String getHeaderTag() {

@Override
public boolean isDecimalMark(char value) {
if (!this.ignoreDecimalAdvice) {
return super.isDecimalMark(value);
if (variableDecimalMark) {
return value == DFLT_DECIMAL_MARK || value == ALT_DECIMAL_MARK;
}

return value == DFLT_DECIMAL_MARK || value == ALT_DECIMAL_MARK;
return super.isDecimalMark(value);
}

boolean initialize(CharacterSet characters) {
Expand All @@ -78,19 +78,28 @@ boolean initialize(CharacterSet characters) {
if (parsedVersion.length > 1) {
this.version = parsedVersion;
final String syntaxVersion = this.version[1];
this.ignoreDecimalAdvice = syntaxVersion.compareTo("4") >= 0;
final boolean v4plus = syntaxVersion.compareTo("4") >= 0;

characters.setClass(componentDelimiter, CharacterClass.COMPONENT_DELIMITER);
characters.setClass(elementDelimiter, CharacterClass.ELEMENT_DELIMITER);

if (syntaxVersion.compareTo("4") >= 0 || releaseIndicator != ' ') {
if (v4plus || !isServiceAdviceSegment(headerTag)) {
/*
* Decimal mark is variable:
* - always in version 4
* - when UNA segment is not received prior to version 4
*/
variableDecimalMark = true;
}

if (v4plus || releaseIndicator != ' ') {
// Must not be blank for version 4 and above, may be blank before version 4 if not used
characters.setClass(releaseIndicator, CharacterClass.RELEASE_CHARACTER);
} else {
releaseIndicator = '\0';
}

if (syntaxVersion.compareTo("4") >= 0) {
if (v4plus) {
// Must not be blank for version 4 and above
characters.setClass(elementRepeater, CharacterClass.ELEMENT_REPEATER);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void parse(IntSupplier inputSource) throws EDIException {
break;
case HEADER_DATA:
case HEADER_INVALID_DATA:
handleStateHeaderData(input);
handleStateHeaderData((char) input);
eventsReady = dialectConfirmed(State.TAG_SEARCH);
break;
case HEADER_SEGMENT_BEGIN:
Expand Down Expand Up @@ -397,8 +397,8 @@ void handleStateInterchangeCandidate(int input) throws EDIException {
openSegment();
}

void handleStateHeaderData(int input) throws EDIException {
dialect.appendHeader(characters, (char) input);
void handleStateHeaderData(char input) throws EDIException {
dialect.appendHeader(characters, input);

switch (characters.getClass(input)) {
case SEGMENT_DELIMITER:
Expand All @@ -412,8 +412,8 @@ void handleStateHeaderData(int input) throws EDIException {
case RELEASE_CHARACTER:
break;
default:
if (dialect.getDecimalMark() != input && !characters.isIgnored(input)) {
buffer.put((char) input);
if (!dialect.isDecimalMark(input) && !characters.isIgnored(input)) {
buffer.put(input);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class TradacomsDialect extends Dialect {
super(State.DialectCode.TRADACOMS, new String[1]);
componentDelimiter = DFLT_COMPONENT_ELEMENT_SEPARATOR;
elementDelimiter = DFLT_DATA_ELEMENT_SEPARATOR;
decimalMark = 0;
releaseIndicator = DFLT_RELEASE_CHARACTER;
elementRepeater = 0;
segmentDelimiter = DFLT_SEGMENT_TERMINATOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static io.xlate.edi.test.StaEDITestUtil.normalizeLines;
import static io.xlate.edi.test.StaEDITestUtil.write;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
Expand Down Expand Up @@ -1864,7 +1865,7 @@ void testGetDelimitersEDIFACT_defaults_v3() throws EDIStreamException {
assertEquals(':', delimiters.get(Delimiters.COMPONENT_ELEMENT));
assertEquals('.', delimiters.get(Delimiters.DECIMAL));
assertEquals('?', delimiters.get(Delimiters.RELEASE));
assertNull(delimiters.get(Delimiters.REPETITION)); // Not introduced until v4
assertFalse(delimiters.containsKey(Delimiters.REPETITION)); // Not introduced until v4

writer.flush();
assertEquals("UNB+UNOA:3+005435656:1+006415160:1+060515:1434+00000000000778'",
Expand Down Expand Up @@ -1910,8 +1911,8 @@ void testGetDelimitersEDIFACT_noRelease_v3() throws EDIStreamException {
assertEquals('+', delimiters.get(Delimiters.DATA_ELEMENT));
assertEquals(':', delimiters.get(Delimiters.COMPONENT_ELEMENT));
assertEquals('.', delimiters.get(Delimiters.DECIMAL));
assertNull(delimiters.get(Delimiters.RELEASE));
assertNull(delimiters.get(Delimiters.REPETITION)); // Not introduced until v4
assertFalse(delimiters.containsKey(Delimiters.RELEASE));
assertFalse(delimiters.containsKey(Delimiters.REPETITION)); // Not introduced until v4

writer.flush();
assertEquals("UNA:+. 'UNB+UNOA:3+005435656:1+006415160:1+060515:1434+00000000000778'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void testBlankReleaseCharVersion4() throws EDIException {
assertEquals('\'', edifact.getSegmentTerminator());
assertEquals('+', edifact.getDataElementSeparator());
assertEquals(':', edifact.getComponentElementSeparator());
assertEquals('.', edifact.getDecimalMark());
assertEquals('.', edifact.getDecimalMark()); // UNA value ignored, per spec
assertEquals('*', edifact.getRepetitionSeparator());
assertEquals(' ', edifact.getReleaseIndicator());
}
Expand Down