From cd1f5bee2a444356fe7874c08328a8d46d4d5aa2 Mon Sep 17 00:00:00 2001 From: hduelme Date: Wed, 4 Sep 2024 00:40:28 +0200 Subject: [PATCH] Add generics to _ArrayIterator and _ArrayEnumeration --- .../src/main/java/freemarker/core/TemplateElement.java | 4 ++-- .../src/main/java/freemarker/core/_ArrayEnumeration.java | 8 ++++---- .../src/main/java/freemarker/core/_ArrayIterator.java | 8 ++++---- .../src/main/java/freemarker/core/_SortedArraySet.java | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/freemarker-core/src/main/java/freemarker/core/TemplateElement.java b/freemarker-core/src/main/java/freemarker/core/TemplateElement.java index 2e79d9345..b79748ade 100644 --- a/freemarker-core/src/main/java/freemarker/core/TemplateElement.java +++ b/freemarker-core/src/main/java/freemarker/core/TemplateElement.java @@ -220,8 +220,8 @@ public int getChildCount() { */ public Enumeration children() { return childBuffer != null - ? new _ArrayEnumeration(childBuffer, childCount) - : Collections.enumeration(Collections.EMPTY_LIST); + ? new _ArrayEnumeration<>(childBuffer, childCount) + : Collections.emptyEnumeration(); } /** diff --git a/freemarker-core/src/main/java/freemarker/core/_ArrayEnumeration.java b/freemarker-core/src/main/java/freemarker/core/_ArrayEnumeration.java index 72212a911..240c31e97 100644 --- a/freemarker-core/src/main/java/freemarker/core/_ArrayEnumeration.java +++ b/freemarker-core/src/main/java/freemarker/core/_ArrayEnumeration.java @@ -23,13 +23,13 @@ import java.util.NoSuchElementException; /** Don't use this; used internally by FreeMarker, might change without notice. */ -public class _ArrayEnumeration implements Enumeration { +public class _ArrayEnumeration implements Enumeration { - private final Object[] array; + private final E[] array; private final int size; private int nextIndex; - public _ArrayEnumeration(Object[] array, int size) { + public _ArrayEnumeration(E[] array, int size) { this.array = array; this.size = size; this.nextIndex = 0; @@ -41,7 +41,7 @@ public boolean hasMoreElements() { } @Override - public Object nextElement() { + public E nextElement() { if (nextIndex >= size) { throw new NoSuchElementException(); } diff --git a/freemarker-core/src/main/java/freemarker/core/_ArrayIterator.java b/freemarker-core/src/main/java/freemarker/core/_ArrayIterator.java index 465ab21ae..739108e62 100644 --- a/freemarker-core/src/main/java/freemarker/core/_ArrayIterator.java +++ b/freemarker-core/src/main/java/freemarker/core/_ArrayIterator.java @@ -23,12 +23,12 @@ import java.util.NoSuchElementException; /** Don't use this; used internally by FreeMarker, might change without notice. */ -public class _ArrayIterator implements Iterator { +public class _ArrayIterator implements Iterator { - private final Object[] array; + private final E[] array; private int nextIndex; - public _ArrayIterator(Object[] array) { + public _ArrayIterator(E[] array) { this.array = array; this.nextIndex = 0; } @@ -39,7 +39,7 @@ public boolean hasNext() { } @Override - public Object next() { + public E next() { if (nextIndex >= array.length) { throw new NoSuchElementException(); } diff --git a/freemarker-core/src/main/java/freemarker/core/_SortedArraySet.java b/freemarker-core/src/main/java/freemarker/core/_SortedArraySet.java index 3cd2fe338..6d9b67ebd 100644 --- a/freemarker-core/src/main/java/freemarker/core/_SortedArraySet.java +++ b/freemarker-core/src/main/java/freemarker/core/_SortedArraySet.java @@ -44,7 +44,7 @@ public boolean contains(Object o) { @Override public Iterator iterator() { - return new _ArrayIterator(array); + return new _ArrayIterator<>(array); } @Override