From 64245284744835ed9bfe6062c9fccccc39172812 Mon Sep 17 00:00:00 2001 From: Jan Hendriks Date: Thu, 4 Jul 2024 09:55:11 +0200 Subject: [PATCH] #6963 Add Qute support to iterate long numbers --- .../src/main/java/io/quarkus/qute/LoopSectionHelper.java | 5 +++++ .../src/test/java/io/quarkus/qute/LoopSectionTest.java | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/LoopSectionHelper.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/LoopSectionHelper.java index a25d8b4b11932..43d7abe826191 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/LoopSectionHelper.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/LoopSectionHelper.java @@ -15,6 +15,7 @@ import java.util.Set; import java.util.concurrent.CompletionStage; import java.util.stream.IntStream; +import java.util.stream.LongStream; import java.util.stream.Stream; import io.quarkus.qute.SectionHelperFactory.SectionInitContext; @@ -84,6 +85,8 @@ private static int extractSize(Object it) { return Array.getLength(it); } else if (it instanceof Integer) { return ((Integer) it); + } else if (it instanceof Long) { + return (((Long) it).intValue()); } else if (it instanceof Collection) { return ((Collection) it).size(); } else if (it instanceof Map) { @@ -101,6 +104,8 @@ private Iterator extractIterator(Object it) { return ((AbstractMap) it).entrySet().iterator(); } else if (it instanceof Integer) { return IntStream.rangeClosed(1, (Integer) it).iterator(); + } else if (it instanceof Long) { + return LongStream.rangeClosed(1, (Long) it).iterator(); } else if (it.getClass().isArray()) { int length = Array.getLength(it); List elements = new ArrayList<>(length); diff --git a/independent-projects/qute/core/src/test/java/io/quarkus/qute/LoopSectionTest.java b/independent-projects/qute/core/src/test/java/io/quarkus/qute/LoopSectionTest.java index e5046d20de327..5e0ccfbbdf8a2 100644 --- a/independent-projects/qute/core/src/test/java/io/quarkus/qute/LoopSectionTest.java +++ b/independent-projects/qute/core/src/test/java/io/quarkus/qute/LoopSectionTest.java @@ -111,6 +111,14 @@ public void testIntegerStream() { engine.parse("{#for i in total}{i}:{/for}").data("total", 3).render()); } + @Test + public void testLongStream() { + Engine engine = Engine.builder().addDefaults().build(); + + assertEquals("1:2:3:", + engine.parse("{#for i in total}{i}:{/for}").data("total", 3L).render()); + } + @Test public void testIterator() { Engine engine = Engine.builder().addDefaults().build();