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

commonMain.it.unibo.tuprolog.solve.channel.impl.AbstractChannelStore.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.channel.impl

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.channel.Channel
import it.unibo.tuprolog.solve.channel.ChannelStore
import it.unibo.tuprolog.unify.Unificator.Companion.matches

abstract class AbstractChannelStore, Self : ChannelStore>(
    protected val channels: Map,
) : ChannelStore, Map by channels {
    override fun toString(): String =
        channels.entries.joinToString(
            separator = ", ",
            prefix = "${this::class.simpleName}(",
            postfix = ")",
        ) {
            "${it.key}->${it.value}"
        }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null || this::class != other::class) return false

        other as AbstractChannelStore<*, *, *>

        if (channels != other.channels) return false

        return true
    }

    override fun hashCode(): Int {
        return channels.hashCode()
    }

    override fun findByTerm(streamTerm: Term): Sequence =
        values.asSequence().filter { it.streamTerm matches streamTerm }

    override fun aliasesOf(channel: C): Sequence =
        entries.asSequence().filter { (_, v) -> v == channel }.map { it.key }.filterNot { it == ChannelStore.CURRENT }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy