From a2be91ea289ddb1a8634c5fd252243f1b9ab7000 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Mon, 17 Aug 2020 10:46:26 +0200 Subject: Implement SelfRepresentingSingletonSet and let `ContentSourceSet` conform to it --- .../kotlin/utilities/SelfRepresentingSingletonSet.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt (limited to 'core/src/main/kotlin/utilities') 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> : Set { + override val size: Int get() = 1 + + override fun contains(element: T): Boolean = this == element + + override fun containsAll(elements: Collection): Boolean = + if (elements.isEmpty()) true + else elements.all { this == it } + + override fun isEmpty(): Boolean = false + + override fun iterator(): Iterator = iterator { + @Suppress("UNCHECKED_CAST") + yield(this@SelfRepresentingSingletonSet as T) + } +} -- cgit