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

net.nemerosa.ontrack.model.structure.Entity.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.structure

import net.nemerosa.ontrack.model.structure.ID.Companion.isDefined

/**
 * An `Entity` is a model object that has an [ID]. The state of this ID will determined the status
 * of this entity:
 *
 *  * *new* - the ID is not [set][ID.isSet].
 *  * *defined* - the ID is [set][ID.isSet].
 *
 */
@OpenEntity
interface Entity {

    /**
     * ID of the entity
     */
    val id: ID

    /**
     * Numeric value of the ID
     *
     * @throws IllegalStateException If the entity is not defined.
     */
    fun id(): Int {
        check(isDefined(id)) {
            "ID of the entity must be defined"
        }
        return id.value
    }

    companion object {

        @JvmStatic
        fun isEntityNew(e: Entity?, message: String) {
            check(e != null && !isDefined(e.id)) { message }
        }

        @JvmStatic
        fun isEntityDefined(e: Entity?, message: String) {
            check(e != null && isDefined(e.id)) { message }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy