Semantic fix for remove of MutablePredicateIterator
This commit is contained in:
parent
9f78291b79
commit
04c295a359
@ -22,6 +22,9 @@ class PredicateIterator<T> : Iterator<T> {
|
||||
|
||||
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<T> : Iterator<T> {
|
||||
|
||||
if (predicate.test(next)) {
|
||||
foundValue = next
|
||||
once = true
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -84,6 +88,10 @@ class MutablePredicateIterator<T> : MutableIterator<T> {
|
||||
}
|
||||
|
||||
override fun remove() {
|
||||
if (!predicateParent.once) {
|
||||
throw NoSuchElementException()
|
||||
}
|
||||
|
||||
return parent.remove()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user