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

jp.nephy.kchroner.plugin.Plugin.kt Maven / Gradle / Ivy

package jp.nephy.kchroner.plugin

import java.io.Closeable
import java.nio.file.Path

data class Plugin(val path: Path?, val instance: Any, private val annotation: jp.nephy.kchroner.api.Plugin): Registrable>, Closeable {
    private val subscriptions = mutableSetOf>()
    private val version: String?
        get() = if (annotation.version.isNotBlank()) {
            annotation.version
        } else {
            null
        }
    val name: String
        get() = if (annotation.name.isNotBlank()) {
            annotation.name
        } else {
            instance.javaClass.simpleName
        } + "(v.$version)"
    val registeredSubscriptions: List>
        get() = subscriptions.toList()

    override fun register(target: Subscription<*>): Boolean {
        return subscriptions.add(target)
    }

    override fun unregister(target: Subscription<*>): Boolean {
        return subscriptions.remove(target)
    }

    override fun equals(other: Any?): Boolean {
        return path == (other as? Plugin)?.path && name == (other as? Plugin)?.name
    }

    override fun hashCode(): Int {
        return path?.hashCode() ?: 0 + 3 * name.hashCode()
    }

    override fun close() {
        subscriptions.forEach { it.close() }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy