Skip to content

Commit

Permalink
Add generics to _ArrayIterator and _ArrayEnumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
hduelme committed Sep 4, 2024
1 parent 30a6e32 commit cd1f5be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> implements Enumeration<E> {

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;
Expand All @@ -41,7 +41,7 @@ public boolean hasMoreElements() {
}

@Override
public Object nextElement() {
public E nextElement() {
if (nextIndex >= size) {
throw new NoSuchElementException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> implements Iterator<E> {

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;
}
Expand All @@ -39,7 +39,7 @@ public boolean hasNext() {
}

@Override
public Object next() {
public E next() {
if (nextIndex >= array.length) {
throw new NoSuchElementException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean contains(Object o) {

@Override
public Iterator<E> iterator() {
return new _ArrayIterator(array);
return new _ArrayIterator<>(array);
}

@Override
Expand Down

0 comments on commit cd1f5be

Please sign in to comment.