1+ // File generated from our OpenAPI spec by Stainless.
2+
13package com.tryfinch.api.core.http
24
5+ import com.tryfinch.api.core.JsonArray
6+ import com.tryfinch.api.core.JsonBoolean
7+ import com.tryfinch.api.core.JsonMissing
8+ import com.tryfinch.api.core.JsonNull
9+ import com.tryfinch.api.core.JsonNumber
10+ import com.tryfinch.api.core.JsonObject
11+ import com.tryfinch.api.core.JsonString
12+ import com.tryfinch.api.core.JsonValue
313import com.tryfinch.api.core.toImmutable
414import java.util.TreeMap
515
@@ -28,6 +38,19 @@ private constructor(
2838 TreeMap (String .CASE_INSENSITIVE_ORDER )
2939 private var size: Int = 0
3040
41+ fun put (name : String , value : JsonValue ): Builder = apply {
42+ when (value) {
43+ is JsonMissing ,
44+ is JsonNull -> {}
45+ is JsonBoolean -> put(name, value.value.toString())
46+ is JsonNumber -> put(name, value.value.toString())
47+ is JsonString -> put(name, value.value)
48+ is JsonArray -> value.values.forEach { put(name, it) }
49+ is JsonObject ->
50+ value.values.forEach { (nestedName, value) -> put(" $name .$nestedName " , value) }
51+ }
52+ }
53+
3154 fun put (name : String , value : String ) = apply {
3255 map.getOrPut(name) { mutableListOf () }.add(value)
3356 size++
@@ -41,15 +64,6 @@ private constructor(
4164 headers.names().forEach { put(it, headers.values(it)) }
4265 }
4366
44- fun remove (name : String ) = apply { size - = map.remove(name).orEmpty().size }
45-
46- fun removeAll (names : Set <String >) = apply { names.forEach(::remove) }
47-
48- fun clear () = apply {
49- map.clear()
50- size = 0
51- }
52-
5367 fun replace (name : String , value : String ) = apply {
5468 remove(name)
5569 put(name, value)
@@ -68,6 +82,15 @@ private constructor(
6882 headers.names().forEach { replace(it, headers.values(it)) }
6983 }
7084
85+ fun remove (name : String ) = apply { size - = map.remove(name).orEmpty().size }
86+
87+ fun removeAll (names : Set <String >) = apply { names.forEach(::remove) }
88+
89+ fun clear () = apply {
90+ map.clear()
91+ size = 0
92+ }
93+
7194 fun build () =
7295 Headers (
7396 map.mapValuesTo(TreeMap (String .CASE_INSENSITIVE_ORDER )) { (_, values) ->
0 commit comments