CronDateTimeScheduler now is internal (again :( )

This commit is contained in:
InsanusMokrassar 2021-01-02 20:13:47 +06:00
parent 0a2b5ef6a0
commit 476239faa6
4 changed files with 65 additions and 13 deletions

View File

@ -2,6 +2,14 @@
## 0.5.0 ## 0.5.0
**BREAKING CHANGES**
* `CronDateTimeScheduler` has been marked as `internal` and no longer accessible outside of internal functions
* Old methods `merge` and `plus` related to `CronDateTimeScheduler` has been marked as `deprecated` and changed their
parameters types - it is `KronScheduler` now
* New methods `merge` has been added
## 0.4.2 ## 0.4.2
* Versions * Versions

View File

@ -0,0 +1,41 @@
package dev.inmo.krontab
import dev.inmo.krontab.collection.CollectionKronScheduler
import dev.inmo.krontab.internal.CronDateTime
import dev.inmo.krontab.internal.CronDateTimeScheduler
/**
* Create new one [CollectionKronScheduler] to include all [KronScheduler]s of [this] [Iterator]
*
* @see CollectionKronScheduler
* @see CollectionKronScheduler.include
*/
fun Iterator<KronScheduler>.merge(): KronScheduler {
val cronDateTimes = mutableListOf<CronDateTime>()
val collectionScheduler = CollectionKronScheduler()
forEach {
when (it) {
is CronDateTimeScheduler -> cronDateTimes.addAll(it.cronDateTimes)
else -> collectionScheduler.include(it)
}
}
if (cronDateTimes.isNotEmpty()) {
collectionScheduler.include(CronDateTimeScheduler(cronDateTimes))
}
return collectionScheduler
}
/**
* Create new one [CollectionKronScheduler] to include all [KronScheduler]s of [this] [Iterator]
*
* @see CollectionKronScheduler
* @see CollectionKronScheduler.include
*/
@Suppress("NOTHING_TO_INLINE")
inline fun Iterable<KronScheduler>.merge(): KronScheduler = iterator().merge()
/**
* @return Vararg shortcut for [merge]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun merge(vararg kronDateTimeSchedulers: KronScheduler) = kronDateTimeSchedulers.iterator().merge()

View File

@ -5,7 +5,6 @@ import dev.inmo.krontab.KronScheduler
import dev.inmo.krontab.anyCronDateTime import dev.inmo.krontab.anyCronDateTime
import dev.inmo.krontab.internal.* import dev.inmo.krontab.internal.*
import dev.inmo.krontab.internal.CronDateTimeScheduler import dev.inmo.krontab.internal.CronDateTimeScheduler
import dev.inmo.krontab.internal.merge
import dev.inmo.krontab.internal.toNearDateTime import dev.inmo.krontab.internal.toNearDateTime
/** /**
@ -20,7 +19,7 @@ data class CollectionKronScheduler internal constructor(
* Add [kronScheduler] into its [schedulers] list * Add [kronScheduler] into its [schedulers] list
* *
* * When [kronScheduler] is [CronDateTimeScheduler] it will merge all [CronDateTimeScheduler]s from [schedulers] list * * When [kronScheduler] is [CronDateTimeScheduler] it will merge all [CronDateTimeScheduler]s from [schedulers] list
* and this [kronScheduler] using [merge] function * and this [kronScheduler] using [mergeCronDateTimeSchedulers] function
* * When [kronScheduler] is [CollectionKronScheduler] it this instance will include all [kronScheduler] * * When [kronScheduler] is [CollectionKronScheduler] it this instance will include all [kronScheduler]
* [schedulers] * [schedulers]
* * Otherwise [kronScheduler] will be added to [schedulers] list * * Otherwise [kronScheduler] will be added to [schedulers] list
@ -37,7 +36,7 @@ data class CollectionKronScheduler internal constructor(
} }
} }
schedulers.add( schedulers.add(
merge(resultCronDateTimes) mergeCronDateTimeSchedulers(resultCronDateTimes)
) )
} }
is CollectionKronScheduler -> kronScheduler.schedulers.forEach { is CollectionKronScheduler -> kronScheduler.schedulers.forEach {

View File

@ -3,6 +3,7 @@ package dev.inmo.krontab.internal
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
import dev.inmo.krontab.KronScheduler import dev.inmo.krontab.KronScheduler
import dev.inmo.krontab.anyCronDateTime import dev.inmo.krontab.anyCronDateTime
import dev.inmo.krontab.collection.plus
/** /**
* Cron-oriented realisation of [KronScheduler] * Cron-oriented realisation of [KronScheduler]
@ -17,8 +18,7 @@ import dev.inmo.krontab.anyCronDateTime
* @see dev.inmo.krontab.builder.buildSchedule * @see dev.inmo.krontab.builder.buildSchedule
* @see dev.inmo.krontab.builder.SchedulerBuilder * @see dev.inmo.krontab.builder.SchedulerBuilder
*/ */
@Deprecated("This class will get internal status in future") internal data class CronDateTimeScheduler internal constructor(
data class CronDateTimeScheduler internal constructor(
internal val cronDateTimes: List<CronDateTime> internal val cronDateTimes: List<CronDateTime>
) : KronScheduler { ) : KronScheduler {
/** /**
@ -31,22 +31,26 @@ data class CronDateTimeScheduler internal constructor(
} }
} }
internal fun mergeCronDateTimeSchedulers(schedulers: List<CronDateTimeScheduler>) = CronDateTimeScheduler(
schedulers.flatMap { it.cronDateTimes }
)
/** /**
* @return New instance of [CronDateTimeScheduler] with all unique [CronDateTimeScheduler.cronDateTimes] of * @return New instance of [CronDateTimeScheduler] with all unique [CronDateTimeScheduler.cronDateTimes] of
* [kronDateTimeSchedulers] included * [kronDateTimeSchedulers] included
*/ */
@Suppress("NOTHING_TO_INLINE") @Deprecated("Will be removed in next major release", ReplaceWith("merge", "dev.inmo.krontab"))
fun merge(kronDateTimeSchedulers: List<CronDateTimeScheduler>) = CronDateTimeScheduler( fun merge(kronSchedulers: List<KronScheduler>) = kronSchedulers.apply { dev.inmo.krontab.merge() }
kronDateTimeSchedulers.flatMap { it.cronDateTimes }.distinct()
)
/** /**
* @return Vararg shortcyut for [merge] * @return Vararg shortcut for [dev.inmo.krontab.merge]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun merge(vararg kronDateTimeSchedulers: CronDateTimeScheduler) = merge(kronDateTimeSchedulers.toList()) @Deprecated("Will be removed in next major release", ReplaceWith("merge", "dev.inmo.krontab"))
inline fun merge(vararg kronDateTimeSchedulers: KronScheduler) = kronDateTimeSchedulers.apply { dev.inmo.krontab.merge() }
/** /**
* Use [merge] operation to internalcreate new [CronDateTimeScheduler] with all [CronDateTimeScheduler.cronDateTimes] * @return Vararg shortcut for [dev.inmo.krontab.merge]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun CronDateTimeScheduler.plus(other: CronDateTimeScheduler) = merge(this, other) @Deprecated("Will be removed in next major release", ReplaceWith("merge", "dev.inmo.krontab"))
inline fun KronScheduler.plus(other: KronScheduler) = this + other