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

import org.jetbrains.dokka.*

@InternalDokkaApi
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)
    }
}