All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lithic.api.core.Utils.kt Maven / Gradle / Ivy

Go to download

The Lithic Developer API is designed to provide a predictable programmatic interface for accessing your Lithic account through an API and transaction webhooks. Note that your API key is a secret and should be treated as such. Don't share it with anyone, including us. We will never ask you for it.

There is a newer version: 0.71.0
Show newest version
@file:JvmName("Utils")

package com.lithic.api.core

import com.google.common.collect.ImmutableListMultimap
import com.google.common.collect.ListMultimap
import com.google.common.collect.Multimaps
import com.lithic.api.errors.LithicInvalidDataException
import java.util.Collections

@JvmSynthetic
internal fun  T?.getOrThrow(name: String): T {
    if (this == null) {
        throw LithicInvalidDataException("'${name}' is not present")
    }

    return this
}

@JvmSynthetic
internal fun  List.toUnmodifiable(): List {
    if (isEmpty()) {
        return Collections.emptyList()
    }

    return Collections.unmodifiableList(this)
}

@JvmSynthetic
internal fun  Map.toUnmodifiable(): Map {
    if (isEmpty()) {
        return Collections.emptyMap()
    }

    return Collections.unmodifiableMap(this)
}

@JvmSynthetic
internal fun  ListMultimap.toUnmodifiable(): ListMultimap {
    if (isEmpty()) {
        return ImmutableListMultimap.of()
    }

    return Multimaps.unmodifiableListMultimap(this)
}

@JvmSynthetic
internal fun ListMultimap.getRequiredHeader(header: String): String {
    val value =
        entries()
            .stream()
            .filter { entry -> entry.key.equals(header, ignoreCase = true) }
            .map { entry -> entry.value }
            .findFirst()
    if (!value.isPresent) {
        throw LithicInvalidDataException("Could not find $header header")
    }
    return value.get()
}

internal interface Enum




© 2015 - 2024 Weber Informatics LLC | Privacy Policy