Skip to content

Commit 8cf6dd4

Browse files
committed
Implement a mutable container for building formats
1 parent 207e0c5 commit 8cf6dd4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2019-2023 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
7+
8+
/**
9+
* An append-only list of constituent formats. Can't be exposed directly due to the variance rules.
10+
*/
11+
internal class AppendableFormatStructure<T> {
12+
private val list: MutableList<NonConcatenatedFormatStructure<T>> = mutableListOf()
13+
fun build(): ConcatenatedFormatStructure<T> = ConcatenatedFormatStructure(list)
14+
fun add(format: FormatStructure<T>) {
15+
/** TODO: use the caches present in [CachedFormatStructure]. */
16+
when (format) {
17+
is NonConcatenatedFormatStructure -> list.add(format)
18+
is ConcatenatedFormatStructure -> format.formats.forEach { list.add(it) }
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)