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 --- core/src/main/kotlin/model/ContentSourceSet.kt | 12 ++---------- .../kotlin/utilities/SelfRepresentingSingletonSet.kt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt (limited to 'core/src/main') diff --git a/core/src/main/kotlin/model/ContentSourceSet.kt b/core/src/main/kotlin/model/ContentSourceSet.kt index 6eee4c94..8a1bf53c 100644 --- a/core/src/main/kotlin/model/ContentSourceSet.kt +++ b/core/src/main/kotlin/model/ContentSourceSet.kt @@ -3,28 +3,20 @@ package org.jetbrains.dokka.model import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.utilities.SelfRepresentingSingletonSet data class ContentSourceSet( val sourceSetIDs: CompositeSourceSetID, val displayName: String, val analysisPlatform: Platform -) { +) : SelfRepresentingSingletonSet { constructor(sourceSet: DokkaSourceSet) : this( sourceSetIDs = CompositeSourceSetID(sourceSet.sourceSetID), displayName = sourceSet.displayName, analysisPlatform = sourceSet.analysisPlatform ) - - operator fun contains(sourceSetID: DokkaSourceSetID): Boolean { - return sourceSetID in sourceSetIDs - } - - operator fun contains(sourceSet: DokkaSourceSet): Boolean { - return sourceSet.sourceSetID in this - } } - fun DokkaSourceSet.toContentSourceSet(): ContentSourceSet = ContentSourceSet(this) fun Iterable.toContentSourceSets(): Set = map { it.toContentSourceSet() }.toSet() 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