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

me.jakejmattson.kutils.api.dsl.command.GenericContainers.kt Maven / Gradle / Ivy

There is a newer version: 0.18.1
Show newest version
package me.jakejmattson.kutils.api.dsl.command

open class GenericContainer
class NoArgs : GenericContainer()
data class Args1(val first: T) : GenericContainer()
data class Args2(val first: A, val second: B) : GenericContainer()
data class Args3(val first: A, val second: B, val third: C) : GenericContainer()
data class Args4(val first: A, val second: B, val third: C, val fourth: D) : GenericContainer()
data class Args5(val first: A, val second: B, val third: C, val fourth: D, val fifth: E) : GenericContainer()

internal fun bundleToArgContainer(arguments: List) =
    when (arguments.size) {
        0 -> NoArgs()
        1 -> Args1(arguments[0])
        2 -> Args2(arguments[0], arguments[1])
        3 -> Args3(arguments[0], arguments[1], arguments[2])
        4 -> Args4(arguments[0], arguments[1], arguments[2], arguments[3])
        5 -> Args5(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4])
        else -> throw IllegalArgumentException("Cannot handle (${arguments.size}) arguments.")
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy