diff options
Diffstat (limited to 'core/src/main/kotlin/utilities')
-rw-r--r-- | core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt new file mode 100644 index 00000000..d384bda4 --- /dev/null +++ b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt @@ -0,0 +1,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) + } +} |