aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt
blob: d384bda4bd4fabc8cf68f262cd3176b0dabcd0b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package org.jetbrains.dokka.utilities

interface SelfRepresentingSingletonSet<T : SelfRepresentingSingletonSet<T>> : Set<T> {
    override val size: Int get() = 1

    override fun contains(element: T): Boolean = this == element

    override fun containsAll(elements: Collection<T>): Boolean =
        if (elements.isEmpty()) true
        else elements.all { this == it }

    override fun isEmpty(): Boolean = false

    override fun iterator(): Iterator<T> = iterator {
        @Suppress("UNCHECKED_CAST")
        yield(this@SelfRepresentingSingletonSet as T)
    }
}