From 7135a62ca33b79ca810aa04ddf03fd680bf33f73 Mon Sep 17 00:00:00 2001 From: Willem Date: Mon, 20 Jan 2025 03:22:20 +0100 Subject: [PATCH] Verious small loop removals --- .../x4o/fc18/FourCornerUnicodeDisplay.java | 18 ++--------- .../org/x4o/fc18/FourCornerUnicodeImport.java | 6 +--- .../fc18/cake2/fcdoc/FCDocSegmentWriter.java | 32 +++++++++---------- .../fcdoc/FCDocSegmentWriterCakeWord.java | 5 --- 4 files changed, 20 insertions(+), 41 deletions(-) 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 435e04f..944fe53 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 @@ -84,11 +84,7 @@ public class FourCornerUnicodeDisplay { public void renderFromX06(List chars, StringBuilder buf) { List charPoints = new ArrayList<>(chars.size()); - for (FourCornerX06BaklavaPointSequence oven : chars) { - for (int v : oven.baklavaPointSequence()) { - charPoints.add(v); - } - } + chars.forEach(v -> charPoints.addAll(v.baklavaPointSequence())); renderFromInt18(charPoints, buf); } @@ -98,11 +94,7 @@ public class FourCornerUnicodeDisplay { public void renderFromX08(List chars, StringBuilder buf) { List charPoints = new ArrayList<>(chars.size()); - for (FourCornerX08MuffinPointSequence oven : chars) { - for (int v : oven.muffinPointSequence()) { - charPoints.add(v); - } - } + chars.forEach(v -> charPoints.addAll(v.muffinPointSequence())); renderFromInt18(charPoints, buf); } @@ -112,11 +104,7 @@ public class FourCornerUnicodeDisplay { public void renderFromX18(List chars, StringBuilder buf) { List charPoints = new ArrayList<>(chars.size()); - for (FourCornerX18CakePointSequence oven : chars) { - for (int v : oven.cakePointSequence()) { - charPoints.add(v); - } - } + chars.forEach(v -> charPoints.addAll(v.cakePointSequence())); renderFromInt18(charPoints, buf); } 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 3e70a41..95dfd85 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 @@ -60,11 +60,7 @@ public class FourCornerUnicodeImport { public List convertToInt18(String text) { List cakePoints = new ArrayList<>(text.length()); - for (FourCornerX18CakePointSequence oven : convertToX18(text)) { - for (int v : oven.cakePointSequence()) { - cakePoints.add(v); - } - } + convertToX18(text).forEach(v -> cakePoints.addAll(v.cakePointSequence())); return cakePoints; } diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriter.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriter.java index 664f9af..ce8b0ad 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriter.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriter.java @@ -44,12 +44,12 @@ public interface FCDocSegmentWriter { default void writeP7x(ApiDocContentWriter writer, FourCornerDotCake slice, Function conv) throws IOException { String prefixHex = String.format("0x%06X", slice.getStart()); try (ContentCloseable tableRow = writer.docTableRow()) { - writer.printTagStart(Tag.td, ApiDocContentCss.colFirst); - writer.printCharacters(prefixHex); - writer.printTagEnd(Tag.td); - writer.printTagStart(Tag.td, ApiDocContentCss.colOne); - writer.printCharacters(slice.nameSpec()); - writer.printTagEnd(Tag.td); + try (ContentCloseable td = writer.printTag(Tag.td, ApiDocContentCss.colFirst)) { + writer.printCharacters(prefixHex); + } + try (ContentCloseable td = writer.printTag(Tag.td, ApiDocContentCss.colOne)) { + writer.printCharacters(slice.nameSpec()); + } for (int i = 0; i < 27; i++) { int codePoint = conv.apply(i); if (i + 1 < 27) { @@ -111,13 +111,13 @@ public interface FCDocSegmentWriter { for (int i = 0; i < headers.length; i++) { atts = new AttributesImpl(); if (i == 0) { - atts.addAttribute ("", "class", "", "", ApiDocContentCss.colFirst.name()); + atts.addAttribute("", "class", "", "", ApiDocContentCss.colFirst.name()); } else if (i == 1) { - atts.addAttribute ("", "class", "", "", ApiDocContentCss.colOne.name()); + atts.addAttribute("", "class", "", "", ApiDocContentCss.colOne.name()); } else { - atts.addAttribute ("", "class", "", "", ApiDocContentCss.colLast.name()); + atts.addAttribute("", "class", "", "", ApiDocContentCss.colLast.name()); } - atts.addAttribute ("", "scope", "", "", "col"); + atts.addAttribute("", "scope", "", "", "col"); try (ContentCloseable th = writer.printTag(Tag.th, atts)) { writer.printCharacters(headers[i]); } @@ -134,20 +134,20 @@ public interface FCDocSegmentWriter { AttributesImpl atts; if (colFirst) { atts = new AttributesImpl(); - atts.addAttribute ("", "class", "", "", ApiDocContentCss.colFirst.name()); - atts.addAttribute ("", "scope", "", "", "col"); + atts.addAttribute("", "class", "", "", ApiDocContentCss.colFirst.name()); + atts.addAttribute("", "scope", "", "", "col"); writer.printTagStart(Tag.th, atts); writer.printTagEnd(Tag.th); } atts = new AttributesImpl(); - atts.addAttribute ("", "class", "", "", ApiDocContentCss.colOne.name()); - atts.addAttribute ("", "scope", "", "", "col"); + atts.addAttribute("", "class", "", "", ApiDocContentCss.colOne.name()); + atts.addAttribute("", "scope", "", "", "col"); writer.printTagStart(Tag.th, atts); writer.printTagEnd(Tag.th); for (int i = 0; i < num - 1; i++) { atts = new AttributesImpl(); - atts.addAttribute ("", "class", "", "", ApiDocContentCss.colLast.name()); - atts.addAttribute ("", "scope", "", "", "col"); + atts.addAttribute("", "class", "", "", ApiDocContentCss.colLast.name()); + atts.addAttribute("", "scope", "", "", "col"); writer.printTagStart(Tag.th, atts); writer.printCharacters("0x"); writer.printCharacters(Integer.toHexString(i).toUpperCase()); diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriterCakeWord.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriterCakeWord.java index e262b38..6dda64c 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriterCakeWord.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/fcdoc/FCDocSegmentWriterCakeWord.java @@ -23,7 +23,6 @@ package org.x4o.fc18.cake2.fcdoc; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -85,10 +84,6 @@ public class FCDocSegmentWriterCakeWord implements FCDocSegmentWriter { writer.docTableEnd(); } - private void writeSequence(ApiDocContentWriter writer, String system, int[] sequence) throws IOException { - writeSequence(writer, system, Arrays.stream(sequence).mapToObj(v -> v).toList()); - } - private void writeSequence(ApiDocContentWriter writer, String system, List sequence) throws IOException { StringBuilder buf = new StringBuilder(); for (int i = 0; i < sequence.size(); i++) {