Added support for iterating over StatList lists

This commit is contained in:
Collin Smith 2020-09-03 18:33:55 -07:00
parent b17f528611
commit a3b3840b20

View File

@ -52,6 +52,7 @@ public final class StatList {
private IndexIterator INDEX_ITERATOR;
private StatIterator STAT_ITERATOR;
private StatListIterator STAT_LIST_ITERATOR;
StatList() {
this(MAX_LISTS);
@ -709,4 +710,39 @@ public final class StatList {
throw new UnsupportedOperationException();
}
}
public StatListIterator listIterator() {
return STAT_LIST_ITERATOR == null
? STAT_LIST_ITERATOR = new StatListIterator().reset()
: STAT_LIST_ITERATOR.reset();
}
public final class StatListIterator implements Iterator<StatListGetter>, Iterable<StatListGetter> {
int list = 0;
StatListIterator reset() {
list = 0;
return this;
}
@Override
public Iterator<StatListGetter> iterator() {
return this;
}
@Override
public boolean hasNext() {
return list < numLists;
}
@Override
public StatListGetter next() {
return get(list++);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}