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

import org.jetbrains.dokka.InternalDokkaApi

@InternalDokkaApi
@Suppress("DEPRECATION_ERROR")
@Deprecated(message = "SelfRepresentingSingletonSet is an incorrect set implementation that breaks set invariants", level = DeprecationLevel.ERROR)
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)
    }
}