From a3b3840b201a1d6f089a5e369024c8d2fcb96da5 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Thu, 3 Sep 2020 18:33:55 -0700 Subject: [PATCH] Added support for iterating over StatList lists --- core/src/com/riiablo/attributes/StatList.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/src/com/riiablo/attributes/StatList.java b/core/src/com/riiablo/attributes/StatList.java index ecb2d056..6f9b3e94 100644 --- a/core/src/com/riiablo/attributes/StatList.java +++ b/core/src/com/riiablo/attributes/StatList.java @@ -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, Iterable { + int list = 0; + + StatListIterator reset() { + list = 0; + return this; + } + + @Override + public Iterator iterator() { + return this; + } + + @Override + public boolean hasNext() { + return list < numLists; + } + + @Override + public StatListGetter next() { + return get(list++); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + } }