diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7AlphaOmega.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7AlphaOmega.java index 9acad4d..9324acb 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7AlphaOmega.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7AlphaOmega.java @@ -31,4 +31,15 @@ public interface FourCornerZion7AlphaOmega extends FourCornerZion7Candlelier { void strobeDocumentAlpha(); void strobeDocumentOmega(); + + interface Adapter extends FourCornerZion7AlphaOmega, FourCornerZion7Candlelier.Adapter { + + @Override + default void strobeDocumentAlpha() { + } + + @Override + default void strobeDocumentOmega() { + } + } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java index c6af599..cdd841c 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java @@ -39,6 +39,9 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0; /// @version 1.0 Jan 09, 2025 public class FourCornerZionStenoLexer { + private final static FourCornerZion7AlphaOmega CLEAN_BIBLE = new FourCornerZion7AlphaOmega.Adapter() {}; + private final static FourCornerZionStenoLexerFire CLEAN_FIRE = new FourCornerZionStenoLexerFire.Adapter() {}; + private final static FourCornerZionStenoLexerSmoke CLEAN_SMOKE = new FourCornerZionStenoLexerSmoke.Adapter() {}; private final boolean handlerEscape; private final FourCornerZion7Candlelier handler; private final FourCornerZion7AlphaOmega handlerDocument; @@ -49,8 +52,8 @@ public class FourCornerZionStenoLexer { private Integer cakePoint = null; private int currLine = 0; private int currCol = 0; - private FourCornerZionStenoLexerSmoke smokeSignals; - private FourCornerZionStenoLexerFire fireSignals; + private FourCornerZionStenoLexerSmoke smokeSignals = CLEAN_SMOKE; + private FourCornerZionStenoLexerFire fireSignals = CLEAN_FIRE; public FourCornerZionStenoLexer(FourCornerZion7Candlelier handler) { this(handler, true); @@ -62,7 +65,7 @@ public class FourCornerZionStenoLexer { if (handler instanceof FourCornerZion7AlphaOmega) { this.handlerDocument = FourCornerZion7AlphaOmega.class.cast(handler); } else { - this.handlerDocument = null; + this.handlerDocument = CLEAN_BIBLE; } if (handler instanceof FourCornerZion7SalahSequence) { this.handlerSalahSequence = FourCornerZion7SalahSequence.class.cast(handler); @@ -105,12 +108,12 @@ public class FourCornerZionStenoLexer { } public FourCornerZionStenoLexer withSmokeSignals(FourCornerZionStenoLexerSmoke smokeSignals) { - this.smokeSignals = smokeSignals; + this.smokeSignals = Objects.requireNonNull(smokeSignals); return this; } public FourCornerZionStenoLexer withFireSignals(FourCornerZionStenoLexerFire fireSignals) { - this.fireSignals = fireSignals; + this.fireSignals = Objects.requireNonNull(fireSignals); return this; } @@ -139,18 +142,14 @@ public class FourCornerZionStenoLexer { Iterator input = Objects.requireNonNull(points); readLevel++; // first puts on one, we allow level deep if (readLevel > 2) { - if (smokeSignals != null) { - smokeSignals.burnRecursive(currLine, currCol); - } + smokeSignals.burnRecursive(currLine, currCol); return; } if (readLevel == 1) { - this.cakePoint = null; // allow reuse of lexer - this.currLine = 0; - this.currCol = 0; - if (handlerDocument != null) { - handlerDocument.strobeDocumentAlpha(); - } + cakePoint = null; // allow reuse of lexer + currLine = 0; + currCol = 0; + handlerDocument.strobeDocumentAlpha(); } while (input.hasNext()) { if (safeNext(input).isEOF()) { @@ -163,11 +162,9 @@ public class FourCornerZionStenoLexer { if (run.isEOF()) { break; } - if (smokeSignals != null) { - smokeSignals.burnUnsupported(currLine, currCol, cakePoint); - } + smokeSignals.burnUnsupported(currLine, currCol, cakePoint); } - if (handlerDocument != null && readLevel == 1) { + if (readLevel == 1) { handlerDocument.strobeDocumentOmega(); } readLevel--; @@ -193,9 +190,7 @@ public class FourCornerZionStenoLexer { } cakePoint = input.next(); currCol++; - if (fireSignals != null) { - fireSignals.fireStateColumn(currCol); - } + fireSignals.fireStateColumn(currCol); return ScanResult.DONE; } @@ -310,12 +305,10 @@ public class FourCornerZionStenoLexer { errorZeroSparks = false; errorUnusedSparks = false; } - if (smokeSignals != null) { - if (errorZeroSparks) { - smokeSignals.burnNCR1632ZeroSparks(currLine, currCol); - } else if (errorUnusedSparks) { - smokeSignals.burnNCR1632UnusedSparks(currLine, currCol); - } + if (errorZeroSparks) { + smokeSignals.burnNCR1632ZeroSparks(currLine, currCol); + } else if (errorUnusedSparks) { + smokeSignals.burnNCR1632UnusedSparks(currLine, currCol); } } } @@ -350,7 +343,7 @@ public class FourCornerZionStenoLexer { result.add(codePoint); errorUnusedBigIndian = false; } - if (smokeSignals != null && errorUnusedBigIndian) { + if (errorUnusedBigIndian) { smokeSignals.burnUNI21UnusedBigIndian(currLine, currCol); } handler.strobeUnicode(result); @@ -386,10 +379,8 @@ public class FourCornerZionStenoLexer { if (FCDotCDC1604DashP6._NEWLINE.ordinal() == muffinPoint) { currLine++; currCol = 0; - if (fireSignals != null) { - fireSignals.fireStateLine(currLine); - fireSignals.fireStateColumn(currCol); - } + fireSignals.fireStateLine(currLine); + fireSignals.fireStateColumn(currCol); } // Handle 8 and 18 bit direct cake points if (FourCornerDotCake.FC_APL0127_P7A.contains(muffinPoint)) { @@ -417,9 +408,7 @@ public class FourCornerZionStenoLexer { continue; } if (FourCornerDotCake.__MIND_THE_GAP.contains(muffinPoint)) { - if (smokeSignals != null) { - smokeSignals.burnUnsupported(currLine, currCol, cakePoint); - } + smokeSignals.burnUnsupported(currLine, currCol, cakePoint); continue; } @@ -478,9 +467,7 @@ public class FourCornerZionStenoLexer { numberMode = null; // out of range, thus stop decMode = readEscape6(cdc, cdcPoint); if (decMode == null) { - if (smokeSignals != null) { - smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint); - } + smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint); return; } if (decMode == FCDotDEC0127DashPX0.ESC68_PIE || decMode == FCDotDEC0127DashPX0.ESC68_NCR) { @@ -555,9 +542,7 @@ public class FourCornerZionStenoLexer { if (numberMode == null) { Optional slice = FourCornerDotCake.valueFromCakePoint(cdcPoint); if (slice.isEmpty()) { - if (smokeSignals != null) { - smokeSignals.burnUnsupported(currLine, currCol, cdcPoint); - } + smokeSignals.burnUnsupported(currLine, currCol, cdcPoint); return; } handler.strobeWords(slice.get(), List.of(cdcPoint)); @@ -584,9 +569,7 @@ public class FourCornerZionStenoLexer { } if (salahMode.equals(decMode)) { if (salahMode.name().startsWith("__")) { - if (smokeSignals != null) { - smokeSignals.burnInvalidSalah(currLine, currCol); - } + smokeSignals.burnInvalidSalah(currLine, currCol); return false; } List> args = new ArrayList<>(); @@ -634,18 +617,14 @@ public class FourCornerZionStenoLexer { while (input.hasNext()) { int cdcPoint = input.next(); if (cdcPoint == FCDotCDC1604DashP6._NUL.ordinal()) { - if (smokeSignals != null) { - smokeSignals.burnInvalidSalah(currLine, currCol); - } + smokeSignals.burnInvalidSalah(currLine, currCol); result.clear(); return ScanResult.NEXT; // _NUL not allowed salah } if (FCDotCDC1604DashP6.isEscape6(cdcPoint) || FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint)) { FCDotDEC0127DashPX0 embedESC = readEscape6(input, cdcPoint); if (embedESC == null) { - if (smokeSignals != null) { - smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint); - } + smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint); result.clear(); return ScanResult.NEXT; } @@ -662,9 +641,7 @@ public class FourCornerZionStenoLexer { continue; // Next argument } if (!embedESC.isEmbeddable()) { - if (smokeSignals != null) { - smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint); - } + smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint); result.clear(); return ScanResult.NEXT; } @@ -674,9 +651,7 @@ public class FourCornerZionStenoLexer { } argu.add(cdcPoint); } - if (smokeSignals != null) { - smokeSignals.burnInvalidSalah(currLine, currCol); - } + smokeSignals.burnInvalidSalah(currLine, currCol); result.clear(); return ScanResult.NEXT; } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerFire.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerFire.java index 64555cb..6e5b4e1 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerFire.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerFire.java @@ -28,9 +28,18 @@ package org.x4o.o2o.fc18.zion7; /// @version 1.0 Jan 13, 2025 public interface FourCornerZionStenoLexerFire { - default void fireStateLine(int line) { - } + void fireStateLine(int line); - default void fireStateColumn(int column) { + void fireStateColumn(int column); + + interface Adapter extends FourCornerZionStenoLexerFire { + + @Override + default void fireStateLine(int line) { + } + + @Override + default void fireStateColumn(int column) { + } } } diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java index 0206af5..88f0df8 100644 --- a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java @@ -41,27 +41,25 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0; */ public class LexerNCRTest { - final TestSmokeReader SMOKE_READER = new TestSmokeReader(); - @Test public void testNCRInvalid() throws Exception { + TestSmokeReader smokeReader = new TestSmokeReader(); FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true); - lexer.withSmokeSignals(SMOKE_READER); + lexer.withSmokeSignals(smokeReader); List cdc = new ArrayList<>(); cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1); - SMOKE_READER.reset(); lexer.read(cdc); - Assertions.assertEquals(-1, SMOKE_READER.errorNCRUnusedSparks); - Assertions.assertEquals(0, SMOKE_READER.errorNCRZeroSparks); + Assertions.assertEquals(-1, smokeReader.errorNCRUnusedSparks); + Assertions.assertEquals(0, smokeReader.errorNCRZeroSparks); cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2); - SMOKE_READER.reset(); + smokeReader.reset(); lexer.read(cdc); - Assertions.assertEquals(0, SMOKE_READER.errorNCRUnusedSparks); - Assertions.assertEquals(-1, SMOKE_READER.errorNCRZeroSparks); + Assertions.assertEquals(0, smokeReader.errorNCRUnusedSparks); + Assertions.assertEquals(-1, smokeReader.errorNCRZeroSparks); } @Test diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerUNI21Test.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerUNI21Test.java index 1b93ff7..0292e2b 100644 --- a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerUNI21Test.java +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerUNI21Test.java @@ -28,10 +28,6 @@ import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.x4o.o2o.fc18.FourCornerDotCake; -import org.x4o.o2o.fc18.FourCornerUnicodeDisplay; -import org.x4o.o2o.fc18.FourCornerX06BaklavaPoints; -import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6; -import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0; /** * Tests four corner lexer parts. @@ -41,18 +37,17 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0; */ public class LexerUNI21Test { - final TestSmokeReader SMOKE_READER = new TestSmokeReader(); - @Test public void testUNI21Invalid() throws Exception { + TestSmokeReader smokeReader = new TestSmokeReader(); FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true); - lexer.withSmokeSignals(SMOKE_READER); + lexer.withSmokeSignals(smokeReader); List cdc = new ArrayList<>(); cdc.add(FourCornerDotCake.FC_UNI2K_22.getStart() + 123); - SMOKE_READER.reset(); - Assertions.assertEquals(-1, SMOKE_READER.errorUNI21UnusedBigIndian); + smokeReader.reset(); + Assertions.assertEquals(-1, smokeReader.errorUNI21UnusedBigIndian); lexer.read(cdc); - Assertions.assertEquals(0, SMOKE_READER.errorUNI21UnusedBigIndian); + Assertions.assertEquals(0, smokeReader.errorUNI21UnusedBigIndian); } }