diff --git a/nx01-mushroom-mais-fc18/src/test/java/love/distributedrebirth/nx01/mushroom/mais/fc18/kanji/KanjiDictTest.java b/nx01-mushroom-mais-fc18/src/test/java/love/distributedrebirth/nx01/mushroom/mais/fc18/kanji/KanjiDictTest.java index 146f209..46dfa2e 100644 --- a/nx01-mushroom-mais-fc18/src/test/java/love/distributedrebirth/nx01/mushroom/mais/fc18/kanji/KanjiDictTest.java +++ b/nx01-mushroom-mais-fc18/src/test/java/love/distributedrebirth/nx01/mushroom/mais/fc18/kanji/KanjiDictTest.java @@ -35,7 +35,7 @@ import java.util.stream.Collectors; import org.x4o.fc18.FourCornerUnicodeDisplay; import org.x4o.fc18.FourCornerUnicodeImport; -import org.x4o.fc18.FourCornerUnicodeMapper; +import org.x4o.fc18.FourCornerRecipe; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; import org.x4o.fc18.cake2.zero33.dec1.FCDotCMD5401Dash2D; import org.x4o.fc18.octal8.PrimordialOctalOrangeString; @@ -81,7 +81,7 @@ public class KanjiDictTest { String valueUnicode = new StringBuilder().appendCodePoint(lit.getCodePoint()).toString(); kuTen2UNI2K.addAll(FourCornerUnicodeImport.strict().convertToInt18(key)); kuTen2UNI2K.add(FCDotCDC1604DashP6.NY09_EQUALS.cakePointDotIndex()); - kuTen2UNI2K.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K(valueUnicode)); + kuTen2UNI2K.addAll(FourCornerRecipe.embedUNI2K(valueUnicode)); kuTen2UNI2K.addAll(FCDotCMD5401Dash2D.CMD_F4TTY0001_NL.cakePointSequence()); } for (String key : dict.mapKuTen213().keySet()) { @@ -89,7 +89,7 @@ public class KanjiDictTest { String valueUnicode = new StringBuilder().appendCodePoint(lit.getCodePoint()).toString(); kuTen2UNI2K.addAll(FourCornerUnicodeImport.strict().convertToInt18(key)); kuTen2UNI2K.add(FCDotCDC1604DashP6.NY09_EQUALS.cakePointDotIndex()); - kuTen2UNI2K.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K(valueUnicode)); + kuTen2UNI2K.addAll(FourCornerRecipe.embedUNI2K(valueUnicode)); kuTen2UNI2K.addAll(FCDotCMD5401Dash2D.CMD_F4TTY0001_NL.cakePointSequence()); } // size 316575 (baklave TTY) diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeMapper.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java similarity index 67% rename from nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeMapper.java rename to nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java index bfae3e2..acc9e72 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeMapper.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java @@ -24,12 +24,8 @@ package org.x4o.fc18; import java.math.BigInteger; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.Optional; import java.util.PrimitiveIterator; import org.x4o.fc18.cake2.FourCornerDotCake; @@ -43,63 +39,16 @@ import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash20; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0; -/// Holds conversion maps between four corner int18 and unicode int21 points. +/// Holds different lookup and conversion maps towards four corner int18 cake points. /// /// @author Willem Cazander /// @version 1.0 Jan 09, 2025 -public enum FourCornerUnicodeMapper { - DICTIONARY, - ; +final public class FourCornerRecipe { - private final Map> int18To21 = new HashMap<>(); - private final Map int21ToVide = new HashMap<>(); - - private FourCornerUnicodeMapper() { - for (FourCornerDotCake slice : FourCornerDotCake.values()) { - FourCornerX00PetitVide[] videPoints = slice.getVidePoints(); - if (videPoints.length == 0) { - continue; - } - mapPointsX18(videPoints); - mapPointsX21(videPoints); - } - int18To21.forEach((k,v) -> int18To21.put(k, Collections.unmodifiableList(v))); + private FourCornerRecipe() { } - private void mapPointsX18(FourCornerX00PetitVide[] petitVides) { - for (FourCornerX00PetitVide petitVide : petitVides) { - Optional x18CakeDotIndex = petitVide.kaasX18CakeDotIndex(); - if (x18CakeDotIndex.isEmpty()) { - continue; - } - int char18 = x18CakeDotIndex.get().cakePointDotIndex(); - petitVide.kaasX21CodeSequence().ifPresent(v -> { - int18To21.put(char18, v.codePointSequence()); - }); - } - } - - private void mapPointsX21(FourCornerX00PetitVide[] petitVides) { - for (FourCornerX00PetitVide petitVide : petitVides) { - petitVide.kaasX21CodeDotIndex().ifPresent(v -> { - int codePoint = v.codePointDotIndex(); - if (codePoint >= 0) { - int21ToVide.put(codePoint, v); - } - }); - } - } - - public List findByX18(Integer letter) { - return int18To21.get(letter); - } - - public FourCornerX00PetitVide findByX21(Integer letter) { - return int21ToVide.get(letter); - } - - // TODO: move this not really unicode related, AND add the muffin version too... move into StenoGrapher later? - public List embedFC18(List cakePoints) { + static public List embedFC18(List cakePoints) { if (cakePoints.isEmpty()) { return cakePoints; } @@ -144,7 +93,7 @@ public enum FourCornerUnicodeMapper { } @Deprecated // TODO: move to sand worm - public List embedUNI2K(String value) { + static public List embedUNI2K(String value) { List result = new ArrayList<>(value.length()); PrimitiveIterator.OfInt i = value.codePoints().iterator(); int bankSelect = 0; @@ -168,21 +117,21 @@ public enum FourCornerUnicodeMapper { return result; } - // todo move... - public List embedNCR1632Denominator(BigInteger value) { + static public List embedNCR1632Denominator(BigInteger value) { return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XD.getStart()); } - // todo move... - public List embedNCR1632Numerator(BigInteger value) { + static public List embedNCR1632Numerator(BigInteger value) { return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XN.getStart()); } - // todo move... - private List embedNCR1632Value(BigInteger value, int bankStart) { + static private List embedNCR1632Value(BigInteger value, int bankStart) { if (value.equals(BigInteger.ZERO)) { throw new IllegalArgumentException("The value ZERO is not allowed."); } + //if (value.signum() == -1) { + // // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options + //} List result = new ArrayList<>(); BigInteger valueZero = value.subtract(BigInteger.ONE); if (valueZero.equals(BigInteger.ZERO)) { @@ -202,28 +151,28 @@ public enum FourCornerUnicodeMapper { reminder = reminder.subtract(BigInteger.valueOf(bankValue).shiftLeft(i * 9)); } if (!reminder.equals(BigInteger.ZERO)) { - throw new IllegalArgumentException("value is larger than 576 bit allowed: " + reminder + " of " + value); + throw new IllegalArgumentException("Value is larger than 576 bit: " + reminder + " of " + value); } return result; } - public List toScriptSuper(int value) { + static public List toScriptSuper(int value) { return toScript(Integer.toString(value), 0); } - public List toScriptSub(int value) { + static public List toScriptSub(int value) { return toScript(Integer.toString(value), 10); } - public List toScriptSuper(BigInteger value) { + static public List toScriptSuper(BigInteger value) { return toScript(value.toString(10), 0); } - public List toScriptSub(BigInteger value) { + static public List toScriptSub(BigInteger value) { return toScript(value.toString(10), 10); } - private List toScript(String value, int off) { + static private List toScript(String value, int off) { List result = new ArrayList<>(); PrimitiveIterator.OfInt i = value.codePoints().iterator(); while (i.hasNext()) { @@ -237,21 +186,21 @@ public enum FourCornerUnicodeMapper { continue; } int num = chr - '0'; - result.add(FCDotPIE9CDash20.values()[num + off]); + result.add(FCDotPIE9CDash20.valueOf(num + off)); } return result; } - public List toDecimalsX06(int value) { + static public List toDecimalsX06(int value) { return toDecimalsX00(value); } - public List toDecimalsX18(int value) { + static public List toDecimalsX18(int value) { return toDecimalsX00(value); } @SuppressWarnings("unchecked") - private List toDecimalsX00(int value) { + static private List toDecimalsX00(int value) { List result = new ArrayList<>(); String valueStr = Integer.toString(value); PrimitiveIterator.OfInt i = valueStr.codePoints().iterator(); diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java index 121e3fd..588b457 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java @@ -226,9 +226,9 @@ public class FourCornerUnicodeDisplay { @Override public void strobeNCR1632(BigInteger denominator, BigInteger numerator) { List math = new ArrayList<>(); - FourCornerUnicodeMapper.DICTIONARY.toScriptSuper(numerator).forEach(v -> math.add(v.cakePointDotIndex())); + FourCornerRecipe.toScriptSuper(numerator).forEach(v -> math.add(v.cakePointDotIndex())); math.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.ordinal()); - FourCornerUnicodeMapper.DICTIONARY.toScriptSub(denominator).forEach(v -> math.add(v.cakePointDotIndex())); + FourCornerRecipe.toScriptSub(denominator).forEach(v -> math.add(v.cakePointDotIndex())); renderFromInt18(math, output); } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeImport.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeImport.java index f6c994c..20c4992 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeImport.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeImport.java @@ -23,12 +23,15 @@ package org.x4o.fc18; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.PrimitiveIterator; import java.util.Set; import java.util.stream.Collectors; +import org.x4o.fc18.cake2.FourCornerDotCake; import org.x4o.fc18.cake2.FourCornerX00PetitVide; import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence; import org.x4o.fc18.cake2.FourCornerX08MuffinPointSequence; @@ -48,6 +51,7 @@ public class FourCornerUnicodeImport { private boolean convertWhitespaces = false; private boolean failOnMissing = false; private List missingCharIndicator = null; + private final Map int21ToVide = new HashMap<>(); private static final Set WHITE_SPACES = Set.of( '\u3000','\u205F','\u202F','\u200A','\u2009','\u2008','\u2007','\u2006', '\u2005','\u2004','\u2003','\u2002','\u2001','\u2000','\u00A0','\u0020') @@ -58,6 +62,24 @@ public class FourCornerUnicodeImport { this.convertDiacritics = convertDiacritics; this.failOnMissing = failOnMissing; this.missingCharIndicator = missingCharIndicator; + for (FourCornerDotCake slice : FourCornerDotCake.values()) { + FourCornerX00PetitVide[] videPoints = slice.getVidePoints(); + if (videPoints.length == 0) { + continue; + } + mapPointsX21(videPoints); + } + } + + private void mapPointsX21(FourCornerX00PetitVide[] petitVides) { + for (FourCornerX00PetitVide petitVide : petitVides) { + petitVide.kaasX21CodeDotIndex().ifPresent(v -> { + int codePoint = v.codePointDotIndex(); + if (codePoint >= 0) { + int21ToVide.put(codePoint, v); + } + }); + } } static public FourCornerUnicodeImport strict() { @@ -231,7 +253,7 @@ public class FourCornerUnicodeImport { } private boolean handleDictionary(ImportState ctx) { - FourCornerX00PetitVide chs = FourCornerUnicodeMapper.DICTIONARY.findByX21(ctx.codePoint); + FourCornerX00PetitVide chs = int21ToVide.get(ctx.codePoint); if (chs == null) { return false; } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/pie9c/FCDotPIE9CDash20.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/pie9c/FCDotPIE9CDash20.java index 911067e..2589518 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/pie9c/FCDotPIE9CDash20.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/pie9c/FCDotPIE9CDash20.java @@ -58,6 +58,7 @@ public enum FCDotPIE9CDash20 implements FourCornerDotCollePie9 { SUB_8('₈'), SUB_9('₉'), ; + static final private FCDotPIE9CDash20[] VALUES = values(); // values() is slow method private final List codePointDisplay; private FCDotPIE9CDash20(int...codePoints) { @@ -78,4 +79,12 @@ public enum FCDotPIE9CDash20 implements FourCornerDotCollePie9 { public List codePointSequence() { return codePointDisplay; } + + static public int valuesLength() { + return VALUES.length; + } + + static public FCDotPIE9CDash20 valueOf(int idx) { + return VALUES[idx]; + } } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java index 908b145..b54b8b1 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java @@ -26,7 +26,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Objects; -import org.x4o.fc18.FourCornerUnicodeMapper; +import org.x4o.fc18.FourCornerRecipe; import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0; import org.x4o.fc18.octal8.PrimordialOctal; @@ -64,8 +64,8 @@ public class FourCornerZionStenoGrapher { @Override public void strobeNCR1632(BigInteger denominator, BigInteger numerator) { - out.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Denominator(denominator)); - out.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Numerator(numerator)); + out.addAll(FourCornerRecipe.embedNCR1632Denominator(denominator)); + out.addAll(FourCornerRecipe.embedNCR1632Numerator(numerator)); } @Override 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 e0708a5..b046550 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 @@ -59,7 +59,7 @@ public class FourCornerZionStenoLexer { private final FourCornerZion7WaterCodex handlerCodex; private final FourCornerZion7SalahSequence handlerSalahSequence; private final FourCornerZion7TempleScrolls handlerTempleScrolls; - private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group of 9 bit values + private final int denominatorBank[] = new int[64]; // <== is the terminator select are 6 bit of banks with 9 bit of values. private final int numeratorBank[] = new int[denominatorBank.length]; private List input; private int inputIndex = 0; diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/FourCornerUnicodeDisplayTest.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/FourCornerUnicodeDisplayTest.java index b1327ee..1d67485 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/FourCornerUnicodeDisplayTest.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/FourCornerUnicodeDisplayTest.java @@ -101,9 +101,9 @@ public class FourCornerUnicodeDisplayTest { List cdc = new ArrayList<>(); cdc.add(FCDotCDC1604DashP6.NX23_W.ordinal()); cdc.add(FCDotCDC1604DashP6.NY09_EQUALS.ordinal()); - cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K("©Δ∞ 仙上主天")); + cdc.addAll(FourCornerRecipe.embedUNI2K("©Δ∞ 仙上主天")); cdc.add(FCDotCDC1604DashP6.NY20_PLUS.ordinal()); - cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.embedUNI2K("𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡 𑀪𑀸𑀕")); + cdc.addAll(FourCornerRecipe.embedUNI2K("𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡 𑀪𑀸𑀕")); cdc.add(FCDotCDC1604DashP6.NY14_SEMICOLON.ordinal()); //cdc.add(FCDotCDC1604DashP6._NEWLINE.ordinal()); @@ -114,7 +114,7 @@ public class FourCornerUnicodeDisplayTest { int bitsFC18 = cdc.size()*18; Assertions.assertTrue(bitsFC18 < bitsUTF8, "FC18 is not smaller"); - List cdc6 = FourCornerUnicodeMapper.DICTIONARY.embedFC18(cdc); + List cdc6 = FourCornerRecipe.embedFC18(cdc); Assertions.assertEquals(outputExpected, FourCornerUnicodeDisplay.text().renderFromInt18(cdc6)); Assertions.assertTrue(cdc6.size() > cdc.size(), "FCx6 is not bigger"); diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotVT06Test.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotVT06Test.java index 89ecffe..a8f4c52 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotVT06Test.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotVT06Test.java @@ -28,7 +28,7 @@ import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.x4o.fc18.FourCornerUnicodeDisplay; -import org.x4o.fc18.FourCornerUnicodeMapper; +import org.x4o.fc18.FourCornerRecipe; import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence; import org.x4o.fc18.cake2.zero33.vt06.VTDash06DotZeroACursor; import org.x4o.fc18.cake2.zero33.vt06.VTDash06DotZeroCClear; @@ -45,9 +45,9 @@ public class FCDotVT06Test { public void testCusorGoto() throws Exception { List cdc = new ArrayList<>(); cdc.add(VTDash06DotZeroACursor.VT_CURSOR_GOTO); - cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.toDecimalsX06(123)); // TODO: fix these are the wrong, we need to use the txt grams version + cdc.addAll(FourCornerRecipe.toDecimalsX06(123)); // TODO: fix these are the wrong, we need to use the txt grams version cdc.add(FCDotCDC1604DashP6._RAKA_QUESTION); - cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.toDecimalsX06(456)); + cdc.addAll(FourCornerRecipe.toDecimalsX06(456)); cdc.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION); Assertions.assertEquals("␘␘␇AG␇␇␇^BCD?␇␇␇^EFG!", FourCornerUnicodeDisplay.raw().renderFromX06(cdc)); @@ -59,7 +59,7 @@ public class FCDotVT06Test { public void testClearTop5Lines() throws Exception { List cdc = new ArrayList<>(); cdc.add(VTDash06DotZeroCClear.VT_CLEAR_TOP); - cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.toDecimalsX06(5)); + cdc.addAll(FourCornerRecipe.toDecimalsX06(5)); cdc.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION); Assertions.assertEquals("␘␘␇CA␇␇␇^F!", FourCornerUnicodeDisplay.raw().renderFromX06(cdc)); diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/LexerNCRTest.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/LexerNCRTest.java index 61b7e2e..a889604 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/LexerNCRTest.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/LexerNCRTest.java @@ -29,7 +29,7 @@ import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.x4o.fc18.FourCornerUnicodeDisplay; -import org.x4o.fc18.FourCornerUnicodeMapper; +import org.x4o.fc18.FourCornerRecipe; import org.x4o.fc18.cake2.FourCornerDotCake; import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; @@ -139,10 +139,10 @@ public class LexerNCRTest { List cdc = new ArrayList<>(); for (int x = 1; x <= 1024; x++) { BigInteger v = BigInteger.valueOf(x); - cdc.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Denominator(v)); + cdc.addAll(FourCornerRecipe.embedNCR1632Denominator(v)); //cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart()); // NXX_1 - List nomList = FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Numerator(BigInteger.ONE); + List nomList = FourCornerRecipe.embedNCR1632Numerator(BigInteger.ONE); Assertions.assertEquals(1, nomList.size()); cdc.addAll(nomList); // NXX_1 }