Skip to content

Commit

Permalink
Fix json iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Oct 26, 2024
1 parent 3d5cc5c commit 4c5ed57
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ internal class JSONArrayTypedIterator<T : Any>(

override fun hasNext() = index < total

override fun next(): T = typeClass.cast(array[index++])
override fun next(): T {
if (!hasNext()) throw NoSuchElementException()
return get(index++)
}

override fun hasPrevious(): Boolean = index > 0

override fun nextIndex(): Int = index + 1
override fun nextIndex(): Int = index

override fun previous(): T = typeClass.cast(array[index--])
override fun previous(): T {
if (!hasPrevious()) throw NoSuchElementException()
return get(--index)
}

override fun previousIndex(): Int = index - 1

private fun get(i: Int): T = typeClass.cast(array[i])
}

0 comments on commit 4c5ed57

Please sign in to comment.