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

com.hp.jipp.encoding.Enum.kt Maven / Gradle / Ivy

// Copyright 2017 HP Development Company, L.P.
// SPDX-License-Identifier: MIT

package com.hp.jipp.encoding

/**
 * A machine-readable integer code paired with a human-readable name.
 *
 * Note: native Java enums are not used because they cannot be extended at runtime to accept unrecognized values.
 */
abstract class Enum {

    abstract val code: Int

    abstract val name: String

    override fun toString() = "$name($code)"

    companion object {
        /** Convert a List of T into a Map of integer codes to T, where T is a Enum subclass. */
        fun  toCodeMap(nameCodes: Iterable): Map =
            nameCodes.map { it.code to it }.toMap()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy