File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
core/common/src/internal/format/parser Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2019-2025 JetBrains s.r.o. and contributors.
3+ * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+ */
5+
6+ package kotlinx.datetime.internal.format.parser
7+
8+ internal class ConcatenatedListView <T >(val list1 : List <T >, val list2 : List <T >) : AbstractList<T>() {
9+ override val size: Int
10+ get() = list1.size + list2.size
11+
12+ override fun get (index : Int ): T = if (index < list1.size) list1[index] else list2[index - list1.size]
13+
14+ override fun iterator (): Iterator <T > = ConcatenatedListViewIterator ()
15+
16+ private inner class ConcatenatedListViewIterator : Iterator <T > {
17+ private val iterators: List <Iterator <T >> = buildList {
18+ collectIterators(list1)
19+ collectIterators(list2)
20+ }
21+ private var index = 0
22+
23+ private fun MutableList<Iterator<T>>.collectIterators (list : List <T >) {
24+ if (list is ConcatenatedListView <T >) {
25+ collectIterators(list.list1)
26+ collectIterators(list.list2)
27+ } else {
28+ add(list.iterator())
29+ }
30+ }
31+
32+ override fun hasNext (): Boolean {
33+ while (index < iterators.size && ! iterators[index].hasNext()) {
34+ index++
35+ }
36+ return index < iterators.size
37+ }
38+
39+ override fun next (): T = iterators[index].next()
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments