From 79d8b977a6cbf77dd7b5c738845468058f3b5f2e Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 16 Jan 2025 14:15:28 +0100 Subject: [PATCH] Made cake point block check scan in steno lexer abstract --- .../fc18/zion7/FourCornerZionStenoLexer.java | 76 ++++++++++++------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java index 4360acc..ef64388 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java @@ -130,8 +130,28 @@ public class FourCornerZionStenoLexer { } } - private interface StenoScanner { - ScanResult scan(Iterator input); + abstract private class StenoScanner { + + private final int blockStart; + private final int blockStop; + + public StenoScanner(int blockStart, int blockStop) { + this.blockStart = blockStart; + this.blockStop = blockStop; + } + + public StenoScanner(FourCornerDotCake cakeSlice) { + this(cakeSlice.getStart(), cakeSlice.getStop()); + } + + final public ScanResult scan(Iterator input) { + if (cakePoint < blockStart || cakePoint > blockStop) { + return ScanResult.NEXT; + } + return process(input); + } + + abstract ScanResult process(Iterator input); } public void read(List points) { @@ -216,19 +236,17 @@ public class FourCornerZionStenoLexer { return ScanResult.DONE; } - class StenoScannerWordCakeSlice implements StenoScanner { + class StenoScannerWordCakeSlice extends StenoScanner { private final FourCornerDotCake cakeSlice; public StenoScannerWordCakeSlice(FourCornerDotCake cakeSlice) { + super(cakeSlice); this.cakeSlice = Objects.requireNonNull(cakeSlice); } @Override - public ScanResult scan(Iterator input) { - if (cakeSlice.containsNot(cakePoint)) { - return ScanResult.NEXT; - } + public ScanResult process(Iterator input) { List result = new ArrayList<>(); ScanResult status = safeReadSliceOffsets(input, cakeSlice.getStart(), cakeSlice.getStop(), result); if (!result.isEmpty()) { @@ -238,13 +256,14 @@ public class FourCornerZionStenoLexer { } } - class StenoScannerNether implements StenoScanner { + class StenoScannerNether extends StenoScanner { + + public StenoScannerNether() { + super(FourCornerDotCake.FC_NETHER); + } @Override - public ScanResult scan(Iterator input) { - if (FourCornerDotCake.FC_NETHER.containsNot(cakePoint)) { - return ScanResult.NEXT; - } + public ScanResult process(Iterator input) { List result = new ArrayList<>(); ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_NETHER.getStart(), FourCornerDotCake.FC_NETHER.getStop(), result); if (!result.isEmpty()) { @@ -259,13 +278,14 @@ public class FourCornerZionStenoLexer { } } - class StenoScannerNCR18 implements StenoScanner { + class StenoScannerNCR18 extends StenoScanner { + + public StenoScannerNCR18() { + super(FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop()); + } @Override - public ScanResult scan(Iterator input) { - if (cakePoint < FourCornerDotCake.FC_NCR1632_XD.getStart() || cakePoint > FourCornerDotCake.FC_NCR1632_XN.getStop()) { - return ScanResult.NEXT; - } + public ScanResult process(Iterator input) { List result = new ArrayList<>(); ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop(), result); if (!result.isEmpty()) { @@ -313,13 +333,14 @@ public class FourCornerZionStenoLexer { } } - class StenoScannerUNI21 implements StenoScanner { + class StenoScannerUNI21 extends StenoScanner { + + public StenoScannerUNI21() { + super(FourCornerDotCake.FC_UNI2K_11.getStart(), FourCornerDotCake.FC_UNI2K_22.getStop()); + } @Override - public ScanResult scan(Iterator input) { - if (cakePoint < FourCornerDotCake.FC_UNI2K_11.getStart() || cakePoint > FourCornerDotCake.FC_UNI2K_22.getStop()) { - return ScanResult.NEXT; - } + public ScanResult process(Iterator input) { List result = new ArrayList<>(); ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_UNI2K_11.getStart(), FourCornerDotCake.FC_UNI2K_22.getStop(), result); if (!result.isEmpty()) { @@ -352,17 +373,18 @@ public class FourCornerZionStenoLexer { } } - class StenoScannerCDCDECMuffin implements StenoScanner { + class StenoScannerCDCDECMuffin extends StenoScanner { private Integer numberMode = null; private boolean numberPIE = true; private FCDotDEC0127DashPX0 decMode = null; + public StenoScannerCDCDECMuffin() { + super(0x00, FourCornerDotCake.__MIND_THE_GAP8.getStop()); + } + @Override - public ScanResult scan(Iterator input) { - if (cakePoint < FourCornerDotCake.FC_CDC1604_P6.getStart() || cakePoint > FourCornerDotCake.__MIND_THE_GAP8.getStop()) { - return ScanResult.NEXT; - } + public ScanResult process(Iterator input) { List result = new ArrayList<>(); ScanResult status = safeReadCakePoints(input, FourCornerDotCake.FC_CDC1604_P6.getStart(), FourCornerDotCake.__MIND_THE_GAP8.getStop(), result); if (!result.isEmpty()) {