diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/PredicateIterator.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/PredicateIterator.kt index ff7c47461..631bd998b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/PredicateIterator.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/PredicateIterator.kt @@ -22,6 +22,9 @@ class PredicateIterator : Iterator { private var foundValue: Any? = Companion + var once: Boolean = false + private set + override fun hasNext(): Boolean { if (foundValue === Companion) { while (parent.hasNext()) { @@ -29,6 +32,7 @@ class PredicateIterator : Iterator { if (predicate.test(next)) { foundValue = next + once = true return true } } @@ -84,6 +88,10 @@ class MutablePredicateIterator : MutableIterator { } override fun remove() { + if (!predicateParent.once) { + throw NoSuchElementException() + } + return parent.remove() } }