You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
Kotlin
46 lines
1.0 KiB
Kotlin
package me.eater.threedom.utils
|
|
|
|
class MutableOrderedSetListIterator<T>(private val collection: OrderedSet<T>, private var index: Int = 0) :
|
|
MutableListIterator<T> {
|
|
|
|
override fun hasPrevious() = collection.size > (index - 1) && index > 1
|
|
|
|
override fun nextIndex() = index + 1
|
|
override fun previous(): T {
|
|
if (!hasPrevious()) {
|
|
throw NoSuchElementException()
|
|
}
|
|
|
|
index = previousIndex()
|
|
return collection[index]
|
|
}
|
|
|
|
override fun previousIndex() = index - 1
|
|
override fun add(element: T) {
|
|
collection.add(index, element)
|
|
}
|
|
|
|
override fun hasNext() = nextIndex() < collection.size
|
|
|
|
override fun next(): T {
|
|
if (!hasNext()) {
|
|
throw NoSuchElementException()
|
|
}
|
|
|
|
index = nextIndex()
|
|
return collection[index]
|
|
}
|
|
|
|
override fun remove() {
|
|
collection.removeAt(index)
|
|
|
|
if (index > 0) {
|
|
index -= 1
|
|
}
|
|
}
|
|
|
|
override fun set(element: T) {
|
|
collection[index] = element
|
|
}
|
|
}
|