Fix emptyIterator making invalid cast
This commit is contained in:
parent
e19b511e6c
commit
80708868d5
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=3.1.2
|
projectVersion=3.1.3
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.kommons.collect
|
|||||||
|
|
||||||
import ru.dbotthepony.kommons.util.KOptional
|
import ru.dbotthepony.kommons.util.KOptional
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.NoSuchElementException
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
import java.util.stream.Collector
|
import java.util.stream.Collector
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
@ -376,8 +377,22 @@ fun <T> Iterator<T>.maybe(): T? {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object EmptyIterator : MutableIterator<Nothing> {
|
||||||
|
override fun hasNext(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun next(): Nothing {
|
||||||
|
throw NoSuchElementException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun remove() {
|
||||||
|
throw NoSuchElementException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun <T> emptyIterator(): MutableIterator<T> {
|
fun <T> emptyIterator(): MutableIterator<T> {
|
||||||
return emptyList<T>().iterator() as MutableIterator<T>
|
return EmptyIterator as MutableIterator<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> iteratorOf(value: T): Iterator<T> {
|
fun <T> iteratorOf(value: T): Iterator<T> {
|
||||||
|
Loading…
Reference in New Issue
Block a user