From e2f54ec3ea0e4d6839ddded607d433d8ed6d519b Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 7 Aug 2025 18:16:01 +0200 Subject: [PATCH] FC18: Removed some unneeded List wrapping in building text output --- .../java/org/x4o/fc18/FourCornerRecipe.java | 95 ++++++++++++------- .../x4o/fc18/FourCornerUnicodeDisplay.java | 4 +- 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java index 54d7484..48897f3 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java @@ -31,7 +31,6 @@ import java.util.PrimitiveIterator; import org.x4o.fc18.cake2.FourCornerDotCake; import org.x4o.fc18.cake2.FourCornerX00PetitVide; import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence; -import org.x4o.fc18.cake2.FourCornerX18CakePointDotIndex; import org.x4o.fc18.cake2.FourCornerX18CakePointSequence; import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash10; import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash11; @@ -45,6 +44,9 @@ import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0; /// @version 1.0 Jan 09, 2025 final public class FourCornerRecipe { + static final private BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF); + static final private BigInteger NCR1632_VALUE_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16); + private FourCornerRecipe() { } @@ -125,18 +127,15 @@ final public class FourCornerRecipe { return embedNCR1632Value(new ArrayList<>(), value, FourCornerDotCake.FC_NCR1632_XN.getStart()); } - static public void embedNCR1632Denominator(List result, BigInteger value) { - embedNCR1632Value(result, value, FourCornerDotCake.FC_NCR1632_XD.getStart()); + static public void embedNCR1632Denominator(List out, BigInteger value) { + embedNCR1632Value(out, value, FourCornerDotCake.FC_NCR1632_XD.getStart()); } - static public void embedNCR1632Numerator(List result, BigInteger value) { - embedNCR1632Value(result, value, FourCornerDotCake.FC_NCR1632_XN.getStart()); + static public void embedNCR1632Numerator(List out, BigInteger value) { + embedNCR1632Value(out, value, FourCornerDotCake.FC_NCR1632_XN.getStart()); } - static final private BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF); - static final private BigInteger NCR1632_VALUE_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16); - - static private List embedNCR1632Value(List result, BigInteger value, int bankStart) { + static private List embedNCR1632Value(List out, BigInteger value, int bankStart) { if (value.equals(BigInteger.ZERO)) { throw new IllegalArgumentException("The value ZERO is not allowed."); } @@ -148,8 +147,8 @@ final public class FourCornerRecipe { } BigInteger valueZero = value.subtract(BigInteger.ONE); if (valueZero.equals(BigInteger.ZERO)) { - result.add(bankStart); - return result; + out.add(bankStart); + return out; } for (int i = 63; i >= 0; i--) { int bankValue = valueZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue(); @@ -157,68 +156,94 @@ final public class FourCornerRecipe { continue; } int cakePoint = bankStart + bankValue + (i * 512); - result.add(cakePoint); + out.add(cakePoint); } - return result; + return out; } - static public List toScriptSuper(int value) { - return toScript(Integer.toString(value), 0); + static public List toScriptSuper(int value) { + return toScript(new ArrayList<>(), Integer.toString(value), 0); } - static public List toScriptSub(int value) { - return toScript(Integer.toString(value), 10); + static public List toScriptSub(int value) { + return toScript(new ArrayList<>(), Integer.toString(value), 10); } - static public List toScriptSuper(BigInteger value) { - return toScript(value.toString(10), 0); + static public List toScriptSuper(BigInteger value) { + return toScript(new ArrayList<>(), value.toString(10), 0); } - static public List toScriptSub(BigInteger value) { - return toScript(value.toString(10), 10); + static public List toScriptSub(BigInteger value) { + return toScript(new ArrayList<>(), value.toString(10), 10); } - static private List toScript(String value, int off) { - List result = new ArrayList<>(); + static public void toScriptSuper(List out, int value) { + toScript(out, Integer.toString(value), 0); + } + + static public void toScriptSub(List out, int value) { + toScript(out, Integer.toString(value), 10); + } + + static public void toScriptSuper(List out, BigInteger value) { + toScript(out, value.toString(10), 0); + } + + static public void toScriptSub(List out, BigInteger value) { + toScript(out, value.toString(10), 10); + } + + static private List toScript(List out, String value, int off) { PrimitiveIterator.OfInt i = value.codePoints().iterator(); while (i.hasNext()) { int chr = i.nextInt(); if (chr == '-') { if (off == 0) { - result.add(FCDotPIE9CDash11.NXX_03); + out.add(FCDotPIE9CDash11.NXX_03.cakePointDotIndex()); } else { - result.add(FCDotPIE9CDash11.NXX_08); + out.add(FCDotPIE9CDash11.NXX_08.cakePointDotIndex()); } continue; } int num = chr - '0'; - result.add(FCDotPIE9CDash20.valueOf(num + off)); + out.add(FCDotPIE9CDash20.valueOf(num + off).cakePointDotIndex()); } - return result; + return out; } + // todo: remove X06 output here ?? + static public List toDecimalsX06(int value) { - return toDecimalsX00(value); + return toDecimalsX00(new ArrayList<>(), value); } static public List toDecimalsX18(int value) { - return toDecimalsX00(value); + return toDecimalsX00(new ArrayList<>(), value); + } + + static public void toDecimalsX06(List out, int value) { + toDecimalsX00(out, value); + } + + static public void toDecimalsX18(List out, int value) { + toDecimalsX00(out, value); } @SuppressWarnings("unchecked") - static private List toDecimalsX00(int value) { - List result = new ArrayList<>(); + static private List toDecimalsX00(List out, int value) { String valueStr = Integer.toString(value); PrimitiveIterator.OfInt i = valueStr.codePoints().iterator(); + boolean first = true; while (i.hasNext()) { int chr = i.nextInt(); int num = chr - '0'; - if (result.isEmpty()) { - result.add((T) FCDotPIE9CDash10.valueOf(num)); // Add escaping only once + if (first) { + first = false; // Add escaping only once + out.add((T) FCDotPIE9CDash10.valueOf(num)); } else { - result.add((T) FCDotCDC1604DashP6.valueOf(FCDotCDC1604DashP6.NX01_A.ordinal() + num)); + out.add((T) FCDotCDC1604DashP6.valueOf(FCDotCDC1604DashP6.NX01_A.ordinal() + num)); } } - return result; + return out; } } 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 588b457..76fb38b 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<>(); - FourCornerRecipe.toScriptSuper(numerator).forEach(v -> math.add(v.cakePointDotIndex())); + FourCornerRecipe.toScriptSuper(math, numerator); math.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.ordinal()); - FourCornerRecipe.toScriptSub(denominator).forEach(v -> math.add(v.cakePointDotIndex())); + FourCornerRecipe.toScriptSub(math, denominator); renderFromInt18(math, output); }