commonMain.implementations.immutableList.AbstractListIterator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-collections-immutable Show documentation
Show all versions of kotlinx-collections-immutable Show documentation
Kotlin Immutable Collections multiplatform library
/*
* Copyright 2016-2019 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/
package kotlinx.collections.immutable.implementations.immutableList
internal abstract class AbstractListIterator(var index: Int, var size: Int) : ListIterator {
override fun hasNext(): Boolean {
return index < size
}
override fun hasPrevious(): Boolean {
return index > 0
}
override fun nextIndex(): Int {
return index
}
override fun previousIndex(): Int {
return index - 1
}
internal fun checkHasNext() {
if (!hasNext())
throw NoSuchElementException()
}
internal fun checkHasPrevious() {
if (!hasPrevious())
throw NoSuchElementException()
}
}
internal class SingleElementListIterator(private val element: E, index: Int): AbstractListIterator(index, 1) {
override fun next(): E {
checkHasNext()
index++
return element
}
override fun previous(): E {
checkHasPrevious()
index--
return element
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy