Skip to content

Commit

Permalink
#6963 Add Qute support to iterate long numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Hendriks committed Jul 4, 2024
1 parent ac13706 commit 6424528
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<Object> elements = new ArrayList<>(length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6424528

Please sign in to comment.