FC18: Removed some unneeded List wrapping in building text output

This commit is contained in:
Willem Cazander 2025-08-07 18:16:01 +02:00
parent d0e68f4d7b
commit e2f54ec3ea
2 changed files with 62 additions and 37 deletions

View file

@ -31,7 +31,6 @@ import java.util.PrimitiveIterator;
import org.x4o.fc18.cake2.FourCornerDotCake; import org.x4o.fc18.cake2.FourCornerDotCake;
import org.x4o.fc18.cake2.FourCornerX00PetitVide; import org.x4o.fc18.cake2.FourCornerX00PetitVide;
import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence; import org.x4o.fc18.cake2.FourCornerX06BaklavaPointSequence;
import org.x4o.fc18.cake2.FourCornerX18CakePointDotIndex;
import org.x4o.fc18.cake2.FourCornerX18CakePointSequence; import org.x4o.fc18.cake2.FourCornerX18CakePointSequence;
import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash10; import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash10;
import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash11; 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 /// @version 1.0 Jan 09, 2025
final public class FourCornerRecipe { 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() { private FourCornerRecipe() {
} }
@ -125,18 +127,15 @@ final public class FourCornerRecipe {
return embedNCR1632Value(new ArrayList<>(), value, FourCornerDotCake.FC_NCR1632_XN.getStart()); return embedNCR1632Value(new ArrayList<>(), value, FourCornerDotCake.FC_NCR1632_XN.getStart());
} }
static public void embedNCR1632Denominator(List<Integer> result, BigInteger value) { static public void embedNCR1632Denominator(List<Integer> out, BigInteger value) {
embedNCR1632Value(result, value, FourCornerDotCake.FC_NCR1632_XD.getStart()); embedNCR1632Value(out, value, FourCornerDotCake.FC_NCR1632_XD.getStart());
} }
static public void embedNCR1632Numerator(List<Integer> result, BigInteger value) { static public void embedNCR1632Numerator(List<Integer> out, BigInteger value) {
embedNCR1632Value(result, value, FourCornerDotCake.FC_NCR1632_XN.getStart()); embedNCR1632Value(out, value, FourCornerDotCake.FC_NCR1632_XN.getStart());
} }
static final private BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF); static private List<Integer> embedNCR1632Value(List<Integer> out, BigInteger value, int bankStart) {
static final private BigInteger NCR1632_VALUE_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
static private List<Integer> embedNCR1632Value(List<Integer> result, BigInteger value, int bankStart) {
if (value.equals(BigInteger.ZERO)) { if (value.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The value ZERO is not allowed."); throw new IllegalArgumentException("The value ZERO is not allowed.");
} }
@ -148,8 +147,8 @@ final public class FourCornerRecipe {
} }
BigInteger valueZero = value.subtract(BigInteger.ONE); BigInteger valueZero = value.subtract(BigInteger.ONE);
if (valueZero.equals(BigInteger.ZERO)) { if (valueZero.equals(BigInteger.ZERO)) {
result.add(bankStart); out.add(bankStart);
return result; return out;
} }
for (int i = 63; i >= 0; i--) { for (int i = 63; i >= 0; i--) {
int bankValue = valueZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue(); int bankValue = valueZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue();
@ -157,68 +156,94 @@ final public class FourCornerRecipe {
continue; continue;
} }
int cakePoint = bankStart + bankValue + (i * 512); int cakePoint = bankStart + bankValue + (i * 512);
result.add(cakePoint); out.add(cakePoint);
} }
return result; return out;
} }
static public List<FourCornerX18CakePointDotIndex> toScriptSuper(int value) { static public List<Integer> toScriptSuper(int value) {
return toScript(Integer.toString(value), 0); return toScript(new ArrayList<>(), Integer.toString(value), 0);
} }
static public List<FourCornerX18CakePointDotIndex> toScriptSub(int value) { static public List<Integer> toScriptSub(int value) {
return toScript(Integer.toString(value), 10); return toScript(new ArrayList<>(), Integer.toString(value), 10);
} }
static public List<FourCornerX18CakePointDotIndex> toScriptSuper(BigInteger value) { static public List<Integer> toScriptSuper(BigInteger value) {
return toScript(value.toString(10), 0); return toScript(new ArrayList<>(), value.toString(10), 0);
} }
static public List<FourCornerX18CakePointDotIndex> toScriptSub(BigInteger value) { static public List<Integer> toScriptSub(BigInteger value) {
return toScript(value.toString(10), 10); return toScript(new ArrayList<>(), value.toString(10), 10);
} }
static private List<FourCornerX18CakePointDotIndex> toScript(String value, int off) { static public void toScriptSuper(List<Integer> out, int value) {
List<FourCornerX18CakePointDotIndex> result = new ArrayList<>(); toScript(out, Integer.toString(value), 0);
}
static public void toScriptSub(List<Integer> out, int value) {
toScript(out, Integer.toString(value), 10);
}
static public void toScriptSuper(List<Integer> out, BigInteger value) {
toScript(out, value.toString(10), 0);
}
static public void toScriptSub(List<Integer> out, BigInteger value) {
toScript(out, value.toString(10), 10);
}
static private List<Integer> toScript(List<Integer> out, String value, int off) {
PrimitiveIterator.OfInt i = value.codePoints().iterator(); PrimitiveIterator.OfInt i = value.codePoints().iterator();
while (i.hasNext()) { while (i.hasNext()) {
int chr = i.nextInt(); int chr = i.nextInt();
if (chr == '-') { if (chr == '-') {
if (off == 0) { if (off == 0) {
result.add(FCDotPIE9CDash11.NXX_03); out.add(FCDotPIE9CDash11.NXX_03.cakePointDotIndex());
} else { } else {
result.add(FCDotPIE9CDash11.NXX_08); out.add(FCDotPIE9CDash11.NXX_08.cakePointDotIndex());
} }
continue; continue;
} }
int num = chr - '0'; 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<FourCornerX06BaklavaPointSequence> toDecimalsX06(int value) { static public List<FourCornerX06BaklavaPointSequence> toDecimalsX06(int value) {
return toDecimalsX00(value); return toDecimalsX00(new ArrayList<>(), value);
} }
static public List<FourCornerX18CakePointSequence> toDecimalsX18(int value) { static public List<FourCornerX18CakePointSequence> toDecimalsX18(int value) {
return toDecimalsX00(value); return toDecimalsX00(new ArrayList<>(), value);
}
static public void toDecimalsX06(List<FourCornerX06BaklavaPointSequence> out, int value) {
toDecimalsX00(out, value);
}
static public void toDecimalsX18(List<FourCornerX06BaklavaPointSequence> out, int value) {
toDecimalsX00(out, value);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static private <T extends FourCornerX00PetitVide> List<T> toDecimalsX00(int value) { static private <T extends FourCornerX00PetitVide> List<T> toDecimalsX00(List<T> out, int value) {
List<T> result = new ArrayList<>();
String valueStr = Integer.toString(value); String valueStr = Integer.toString(value);
PrimitiveIterator.OfInt i = valueStr.codePoints().iterator(); PrimitiveIterator.OfInt i = valueStr.codePoints().iterator();
boolean first = true;
while (i.hasNext()) { while (i.hasNext()) {
int chr = i.nextInt(); int chr = i.nextInt();
int num = chr - '0'; int num = chr - '0';
if (result.isEmpty()) { if (first) {
result.add((T) FCDotPIE9CDash10.valueOf(num)); // Add escaping only once first = false; // Add escaping only once
out.add((T) FCDotPIE9CDash10.valueOf(num));
} else { } 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;
} }
} }

View file

@ -226,9 +226,9 @@ public class FourCornerUnicodeDisplay {
@Override @Override
public void strobeNCR1632(BigInteger denominator, BigInteger numerator) { public void strobeNCR1632(BigInteger denominator, BigInteger numerator) {
List<Integer> math = new ArrayList<>(); List<Integer> math = new ArrayList<>();
FourCornerRecipe.toScriptSuper(numerator).forEach(v -> math.add(v.cakePointDotIndex())); FourCornerRecipe.toScriptSuper(math, numerator);
math.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.ordinal()); math.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.ordinal());
FourCornerRecipe.toScriptSub(denominator).forEach(v -> math.add(v.cakePointDotIndex())); FourCornerRecipe.toScriptSub(math, denominator);
renderFromInt18(math, output); renderFromInt18(math, output);
} }