package me.eater.threedom.utils class MutableOrderedSetListIterator(private val collection: OrderedSet, private var index: Int = 0) : MutableListIterator { 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 } }