From 346672b32b8cd712caada127e0455e5fc8abf380 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 4 Dec 2020 22:59:30 +0600 Subject: [PATCH 1/7] start 0.5.0 --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e922d..24131f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.5.0 + ## 0.4.0 **BREAKING CHANGES** diff --git a/build.gradle b/build.gradle index cf3dcc9..fe7849f 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ plugins { id "org.jetbrains.dokka" version "$dokka_version" } -project.version = "0.4.0" +project.version = "0.5.0" project.group = "dev.inmo" apply from: "publish.gradle" From a38c233bbfae71a9dea148ed9a8378c95d8e2782 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Dec 2020 00:01:02 +0600 Subject: [PATCH 2/7] downgrade version to 0.4.1 --- CHANGELOG.md | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24131f4..93f840e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 0.5.0 +## 0.4.1 ## 0.4.0 diff --git a/build.gradle b/build.gradle index fe7849f..25509ab 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ plugins { id "org.jetbrains.dokka" version "$dokka_version" } -project.version = "0.5.0" +project.version = "0.4.1" project.group = "dev.inmo" apply from: "publish.gradle" From 3c0818cabf1cfe8fee9ec03e494504ebc038dd7e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Dec 2020 01:00:57 +0600 Subject: [PATCH 3/7] CollectionKronScheduler --- CHANGELOG.md | 2 + .../krontab/collection/CollectionFunctions.kt | 25 +++++++++++ .../collection/CollectionKronScheduler.kt | 41 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionFunctions.kt create mode 100644 src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f840e..23feab0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.4.1 +* Add `CollectionKronScheduler`. It will give opportunity to unite several schedulers in one + ## 0.4.0 **BREAKING CHANGES** diff --git a/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionFunctions.kt b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionFunctions.kt new file mode 100644 index 0000000..44b03a2 --- /dev/null +++ b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionFunctions.kt @@ -0,0 +1,25 @@ +package dev.inmo.krontab.collection + +import dev.inmo.krontab.KronScheduler + +@Suppress("NOTHING_TO_INLINE") +inline fun CollectionKronScheduler.includeAll(kronSchedulers: List) { + kronSchedulers.forEach { + include(it) + } +} + +@Suppress("NOTHING_TO_INLINE") +inline fun CollectionKronScheduler.includeAll(vararg kronSchedulers: KronScheduler) { + includeAll(kronSchedulers.toList()) +} + +operator fun KronScheduler.plus(kronScheduler: KronScheduler): CollectionKronScheduler { + return CollectionKronScheduler().apply { + includeAll(this, kronScheduler) + } +} + +operator fun CollectionKronScheduler.plusAssign(kronScheduler: KronScheduler) { + include(kronScheduler) +} diff --git a/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt new file mode 100644 index 0000000..e819d16 --- /dev/null +++ b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt @@ -0,0 +1,41 @@ +package dev.inmo.krontab.collection + +import com.soywiz.klock.DateTime +import dev.inmo.krontab.KronScheduler +import dev.inmo.krontab.anyCronDateTime +import dev.inmo.krontab.internal.CronDateTimeScheduler +import dev.inmo.krontab.internal.toNearDateTime + +data class CollectionKronScheduler private constructor( + internal val schedulers: MutableList +) : KronScheduler { + internal constructor(schedulers: List) : this(schedulers.toMutableList()) + internal constructor() : this(mutableListOf()) + + fun include(kronScheduler: KronScheduler) { + when (kronScheduler) { + is CronDateTimeScheduler -> { + val resultCronDateTimes = kronScheduler.cronDateTimes.toMutableList() + schedulers.removeAll { + if (it is CronDateTimeScheduler) { + resultCronDateTimes.addAll(it.cronDateTimes) + true + } else { + false + } + } + schedulers.add( + CronDateTimeScheduler(resultCronDateTimes.distinct()) + ) + } + is CollectionKronScheduler -> kronScheduler.schedulers.forEach { + include(it) + } + else -> schedulers.add(kronScheduler) + } + } + + override suspend fun next(relatively: DateTime): DateTime { + return schedulers.minOfOrNull { it.next(relatively) } ?: anyCronDateTime.toNearDateTime(relatively) + } +} From 05af4d1f67d20ee4227237588766c6fb25a4b84b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Dec 2020 01:03:24 +0600 Subject: [PATCH 4/7] update dependencies --- CHANGELOG.md | 3 +++ gradle.properties | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23feab0..1f6325b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.4.1 +* Versions: + * `Coroutines`: `1.4.1` -> `1.4.2` + * `Klock`: `2.0.0` -> `2.0.1` * Add `CollectionKronScheduler`. It will give opportunity to unite several schedulers in one ## 0.4.0 diff --git a/gradle.properties b/gradle.properties index 8784046..9b086d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.parallel=true kotlin.js.generate.externals=true kotlin.incremental=true kotlin.incremental.js=true +kotlin.incremental.multiplatform=true kotlin_version=1.4.20 -kotlin_coroutines_version=1.4.1 +kotlin_coroutines_version=1.4.2 dokka_version=0.10.1 -klockVersion=2.0.0 +klockVersion=2.0.1 github_release_plugin_version=2.2.12 -kotlin.incremental.multiplatform=true From 3162780447af98a1460867f3f7427e03d60c10bc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Dec 2020 01:40:29 +0600 Subject: [PATCH 5/7] update kdocs --- dokka.gradle | 43 ++++++++----------- gradle.properties | 2 +- .../collection/CollectionKronScheduler.kt | 21 +++++++-- .../krontab/internal/CronDateTimeScheduler.kt | 8 ++++ 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/dokka.gradle b/dokka.gradle index 3b006a7..dea94a8 100644 --- a/dokka.gradle +++ b/dokka.gradle @@ -1,6 +1,4 @@ -dokka { - outputFormat = 'html' - +dokkaHtml { switch (true) { case project.hasProperty("DOKKA_PATH"): outputDirectory = project.property("DOKKA_PATH").toString() @@ -10,33 +8,30 @@ dokka { break } - multiplatform { - global { - perPackageOption { - prefix = "dev.inmo" - skipDeprecated = true - includeNonPublic = true - reportUndocumented = true - } + dokkaSourceSets { + configureEach { + skipDeprecated.set(true) + includeNonPublic.set(true) + reportUndocumented.set(true) sourceLink { - path = "./" - url = "https://github.com/InsanusMokrassar/krontab/blob/master/" - lineSuffix = "#L" + localDirectory.set(file("./")) + remoteUrl.set(new URL("https://github.com/InsanusMokrassar/krontab/blob/master/")) + remoteLineSuffix.set("#L") } } - common { - targets = ["JVM", "JS"] + named("commonMain") { sourceRoot { path = "src/commonMain" } } - js { - targets = ["JS"] - sourceRoot { path = "src/jsMain" } - } - jvm { - targets = ["JVM"] - sourceRoot { path = "src/jvmMain" } - } + +// +// named("jsMain") { +// sourceRoot { path = "src/jsMain" } +// } +// +// named("jvmMain") { +// sourceRoot { path = "src/jvmMain" } +// } } } diff --git a/gradle.properties b/gradle.properties index 9b086d5..83a5763 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ kotlin.incremental.multiplatform=true kotlin_version=1.4.20 kotlin_coroutines_version=1.4.2 -dokka_version=0.10.1 +dokka_version=1.4.20 klockVersion=2.0.1 diff --git a/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt index e819d16..2c6ad20 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt @@ -3,29 +3,42 @@ package dev.inmo.krontab.collection import com.soywiz.klock.DateTime import dev.inmo.krontab.KronScheduler import dev.inmo.krontab.anyCronDateTime +import dev.inmo.krontab.internal.* import dev.inmo.krontab.internal.CronDateTimeScheduler +import dev.inmo.krontab.internal.merge import dev.inmo.krontab.internal.toNearDateTime +/** + * This scheduler will be useful in case you want to unite several different [KronScheduler]s + */ data class CollectionKronScheduler private constructor( internal val schedulers: MutableList ) : KronScheduler { internal constructor(schedulers: List) : this(schedulers.toMutableList()) internal constructor() : this(mutableListOf()) + /** + * Add [kronScheduler] into its [schedulers] list + * + * * When [kronScheduler] is [CronDateTimeScheduler] it will merge all [CronDateTimeScheduler]s from [schedulers] list + * and this [kronScheduler] using [merge] function + * * When [kronScheduler] is [CollectionKronScheduler] it this instance will include all [kronScheduler] + * [schedulers] + * * Otherwise [kronScheduler] will be added to [schedulers] list + */ fun include(kronScheduler: KronScheduler) { when (kronScheduler) { is CronDateTimeScheduler -> { - val resultCronDateTimes = kronScheduler.cronDateTimes.toMutableList() + val resultCronDateTimes = mutableListOf(kronScheduler) schedulers.removeAll { if (it is CronDateTimeScheduler) { - resultCronDateTimes.addAll(it.cronDateTimes) - true + resultCronDateTimes.add(it) } else { false } } schedulers.add( - CronDateTimeScheduler(resultCronDateTimes.distinct()) + merge(resultCronDateTimes) ) } is CollectionKronScheduler -> kronScheduler.schedulers.forEach { diff --git a/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt index c178620..5d83a3c 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt @@ -30,3 +30,11 @@ internal data class CronDateTimeScheduler internal constructor( } } +/** + * @return New instance of [CronDateTimeScheduler] with all unique [CronDateTimeScheduler.cronDateTimes] of + * [kronDateTimeSchedulers] included + */ +@Suppress("NOTHING_TO_INLINE") +internal inline fun merge(kronDateTimeSchedulers: List) = CronDateTimeScheduler( + kronDateTimeSchedulers.flatMap { it.cronDateTimes }.distinct() +) From 4995a34c1a742083c6c5c2153902d8f3bfe2fc0d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Dec 2020 01:44:24 +0600 Subject: [PATCH 6/7] CronDateTimeScheduler adding --- CHANGELOG.md | 2 ++ .../krontab/internal/CronDateTimeScheduler.kt | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f6325b..c6ae625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * Versions: * `Coroutines`: `1.4.1` -> `1.4.2` * `Klock`: `2.0.0` -> `2.0.1` +* `CronDateTimeScheduler` now is public +* New functions for `CronDateTimeScheduler` * Add `CollectionKronScheduler`. It will give opportunity to unite several schedulers in one ## 0.4.0 diff --git a/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt index 5d83a3c..db6873a 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTimeScheduler.kt @@ -17,7 +17,7 @@ import dev.inmo.krontab.anyCronDateTime * @see dev.inmo.krontab.builder.buildSchedule * @see dev.inmo.krontab.builder.SchedulerBuilder */ -internal data class CronDateTimeScheduler internal constructor( +data class CronDateTimeScheduler internal constructor( internal val cronDateTimes: List ) : KronScheduler { /** @@ -35,6 +35,17 @@ internal data class CronDateTimeScheduler internal constructor( * [kronDateTimeSchedulers] included */ @Suppress("NOTHING_TO_INLINE") -internal inline fun merge(kronDateTimeSchedulers: List) = CronDateTimeScheduler( +fun merge(kronDateTimeSchedulers: List) = CronDateTimeScheduler( kronDateTimeSchedulers.flatMap { it.cronDateTimes }.distinct() ) + +/** + * @return Vararg shortcyut for [merge] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun merge(vararg kronDateTimeSchedulers: CronDateTimeScheduler) = merge(kronDateTimeSchedulers.toList()) +/** + * Use [merge] operation to internalcreate new [CronDateTimeScheduler] with all [CronDateTimeScheduler.cronDateTimes] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun CronDateTimeScheduler.plus(other: CronDateTimeScheduler) = merge(this, other) From ca248a25ad5e6ec9957704afb3131017727aa753 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Dec 2020 01:48:00 +0600 Subject: [PATCH 7/7] compile fixes --- .../dev/inmo/krontab/collection/CollectionKronScheduler.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt index 2c6ad20..f5a4263 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/collection/CollectionKronScheduler.kt @@ -11,10 +11,9 @@ import dev.inmo.krontab.internal.toNearDateTime /** * This scheduler will be useful in case you want to unite several different [KronScheduler]s */ -data class CollectionKronScheduler private constructor( +data class CollectionKronScheduler internal constructor( internal val schedulers: MutableList ) : KronScheduler { - internal constructor(schedulers: List) : this(schedulers.toMutableList()) internal constructor() : this(mutableListOf()) /**