diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-17 10:46:26 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-17 11:52:28 +0200 |
commit | a2be91ea289ddb1a8634c5fd252243f1b9ab7000 (patch) | |
tree | 682463697296d7084d70ceb2816e65badf668fd0 /core/src/main/kotlin/utilities | |
parent | b439f0f4da19273a1b60df45aa380ecf2511de73 (diff) | |
download | dokka-a2be91ea289ddb1a8634c5fd252243f1b9ab7000.tar.gz dokka-a2be91ea289ddb1a8634c5fd252243f1b9ab7000.tar.bz2 dokka-a2be91ea289ddb1a8634c5fd252243f1b9ab7000.zip |
Implement SelfRepresentingSingletonSet and let `ContentSourceSet` conform to it
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) + } +} |