com.increase.api.core.Utils.kt Maven / Gradle / Ivy
@file:JvmName("Utils")
package com.increase.api.core
import com.increase.api.core.http.Headers
import com.increase.api.errors.IncreaseInvalidDataException
import java.util.Collections
import java.util.SortedMap
internal fun T?.getOrThrow(name: String): T =
this ?: throw IncreaseInvalidDataException("`${name}` is not present")
internal fun List.toImmutable(): List =
if (isEmpty()) Collections.emptyList() else Collections.unmodifiableList(toList())
internal fun Map.toImmutable(): Map =
if (isEmpty()) Collections.emptyMap() else Collections.unmodifiableMap(toMap())
internal fun , V> SortedMap.toImmutable(): SortedMap =
if (isEmpty()) Collections.emptySortedMap()
else Collections.unmodifiableSortedMap(toSortedMap(comparator()))
internal fun Headers.getRequiredHeader(name: String): String =
values(name).firstOrNull() ?: throw IncreaseInvalidDataException("Could not find $name header")
internal interface Enum
© 2015 - 2024 Weber Informatics LLC | Privacy Policy