aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/model/ContentSourceSet.kt12
-rw-r--r--core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt18
2 files changed, 20 insertions, 10 deletions
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<ContentSourceSet> {
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<DokkaSourceSet>.toContentSourceSets(): Set<ContentSourceSet> = 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<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)
+ }
+}