commonMain.it.unibo.tuprolog.collections.AbstractClauseCollection.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of theory-metadata Show documentation
Show all versions of theory-metadata Show documentation
In-memory storage and indexing facilities for ordered and unordered knowledge bases composed by logic clauses
package it.unibo.tuprolog.collections
import it.unibo.tuprolog.collections.rete.custom.ReteTree
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.theory.TheoryUtils
internal abstract class AbstractClauseCollection>
protected constructor(protected val rete: ReteTree) : ClauseCollection {
override val size: Int
get() = rete.clauses.count()
override fun isEmpty(): Boolean =
size == 0
override fun contains(element: Clause): Boolean =
rete.get(element).any()
override fun containsAll(elements: Iterable): Boolean =
elements.all { it in this }
abstract override fun add(clause: Clause): Self
abstract override fun addAll(clauses: Iterable): Self
abstract override fun retrieve(clause: Clause): RetrieveResult
abstract override fun retrieveAll(clause: Clause): RetrieveResult
override fun iterator(): Iterator =
rete.clauses.iterator()
override fun toString(): String {
return "${this::class.simpleName}(${this.joinToString(", ")})"
}
}