From cef2081a13b47ace9df2b07143dc4d65f8a25dfb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Sep 2021 11:57:55 +0600 Subject: [PATCH 1/5] start 0.5.25 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c8f38e77cd..47cc166c082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.5.25 + ## 0.5.24 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 0bb6ea64dc4..d54839fe079 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,5 +45,5 @@ dokka_version=1.5.0 # Project data group=dev.inmo -version=0.5.24 -android_code_version=65 +version=0.5.25 +android_code_version=66 From d50dffec8ce5eeb52c3bd3abeed69afd73714367 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Sep 2021 12:01:02 +0600 Subject: [PATCH 2/5] update dependencies --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47cc166c082..436ec5543a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.5.25 +* `Versions`: + * `UUID`: `0.3.0` -> `0.3.1` + ## 0.5.24 * `Versions`: diff --git a/gradle.properties b/gradle.properties index d54839fe079..2f8f59b988c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ klockVersion=2.4.1 github_release_plugin_version=2.2.12 -uuidVersion=0.3.0 +uuidVersion=0.3.1 # ANDROID From 925702d315603973ae24f9a26da6349dd83f76ca Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Sep 2021 12:06:23 +0600 Subject: [PATCH 3/5] MPPFile#withoutSlashAtTheEnd --- CHANGELOG.md | 2 ++ .../commonMain/kotlin/dev/inmo/micro_utils/common/MPPFile.kt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 436ec5543a7..bee7a514b15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * `Versions`: * `UUID`: `0.3.0` -> `0.3.1` +* `Common`: + * New property `MPPFile#withoutSlashAtTheEnd` ## 0.5.24 diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/MPPFile.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/MPPFile.kt index c60eb0d6b80..8aada0ca9c7 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/MPPFile.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/MPPFile.kt @@ -7,7 +7,7 @@ import kotlin.jvm.JvmInline @JvmInline value class FileName(val string: String) { val name: String - get() = string.takeLastWhile { it != '/' } + get() = withoutSlashAtTheEnd.takeLastWhile { it != '/' } val extension: String get() = name.takeLastWhile { it != '.' } val nameWithoutExtension: String @@ -17,6 +17,8 @@ value class FileName(val string: String) { filename.substring(0, it) } ?: filename } + val withoutSlashAtTheEnd: String + get() = string.dropLastWhile { it == '/' } override fun toString(): String = string } From ef9af719602d0a062132e51a50ee802ea792c2b8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Sep 2021 12:10:32 +0600 Subject: [PATCH 4/5] clamp deprecation and Iterable#diff --- CHANGELOG.md | 2 ++ .../dev/inmo/micro_utils/common/Clamp.kt | 9 ++------- .../dev/inmo/micro_utils/common/DiffUtils.kt | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bee7a514b15..7f3a78d427c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * `UUID`: `0.3.0` -> `0.3.1` * `Common`: * New property `MPPFile#withoutSlashAtTheEnd` + * Extension `clamp` has been deprecated + * New extension `Iterable#diff` ## 0.5.24 diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt index 98eab69372c..7d6159ca5f7 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt @@ -1,10 +1,5 @@ package dev.inmo.micro_utils.common +@Deprecated("Redundant", ReplaceWith("coerceIn(min, max)")) @Suppress("NOTHING_TO_INLINE") -inline fun > T.clamp(min: T, max: T): T { - return when { - this < min -> min - this > max -> max - else -> this - } -} +inline fun > T.clamp(min: T, max: T): T = coerceIn(min, max) diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt index 0c63e30c786..221237b4fee 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt @@ -2,6 +2,8 @@ package dev.inmo.micro_utils.common +import kotlin.jvm.JvmInline + private inline fun getObject( additional: MutableList, iterator: Iterator @@ -27,8 +29,8 @@ data class Diff internal constructor( private inline fun performChanges( potentialChanges: MutableList?, IndexedValue?>>, - additionalsInOld: MutableList, - additionalsInNew: MutableList, + additionsInOld: MutableList, + additionsInNew: MutableList, changedList: MutableList, IndexedValue>>, removedList: MutableList>, addedList: MutableList>, @@ -52,20 +54,20 @@ private inline fun performChanges( newPotentials.first().second ?.let { addedList.add(it) } newPotentials.drop(1).take(newPotentials.size - 2).forEach { (oldOne, newOne) -> addedList.add(newOne!!) - oldOne ?.let { additionalsInOld.add(oldOne.value) } + oldOne ?.let { additionsInOld.add(oldOne.value) } } if (newPotentials.size > 1) { - newPotentials.last().first ?.value ?.let { additionalsInOld.add(it) } + newPotentials.last().first ?.value ?.let { additionsInOld.add(it) } } } newOneEqualToOldObject -> { newPotentials.first().first ?.let { removedList.add(it) } newPotentials.drop(1).take(newPotentials.size - 2).forEach { (oldOne, newOne) -> removedList.add(oldOne!!) - newOne ?.let { additionalsInNew.add(newOne.value) } + newOne ?.let { additionsInNew.add(newOne.value) } } if (newPotentials.size > 1) { - newPotentials.last().second ?.value ?.let { additionalsInNew.add(it) } + newPotentials.last().second ?.value ?.let { additionsInNew.add(it) } } } } @@ -139,6 +141,10 @@ fun Iterable.calculateDiff( return Diff(removedObjects.toList(), changedObjects.toList(), addedObjects.toList()) } +inline fun Iterable.diff( + other: Iterable, + strictComparison: Boolean = false +): Diff = calculateDiff(other, strictComparison) inline fun Diff(old: Iterable, new: Iterable) = old.calculateDiff(new) inline fun StrictDiff(old: Iterable, new: Iterable) = old.calculateDiff(new, true) From a24a335743f49e142e38738b77cb33d96032c9d8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Sep 2021 12:18:42 +0600 Subject: [PATCH 5/5] TypedSerializer#plusAssign and TypedSerializer#minusAssign --- CHANGELOG.md | 2 ++ .../typed_serializer/TypedSerializer.kt | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f3a78d427c..82782f96337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ * New property `MPPFile#withoutSlashAtTheEnd` * Extension `clamp` has been deprecated * New extension `Iterable#diff` +* `Serialization`: + * New operators `TypedSerializer#plusAssign` and `TypedSerializer#minusAssign` ## 0.5.24 diff --git a/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt b/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt index 158d22994e5..3e6d9045f34 100644 --- a/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt +++ b/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt @@ -11,6 +11,7 @@ open class TypedSerializer( presetSerializers: Map> = emptyMap(), ) : KSerializer { protected val serializers = presetSerializers.toMutableMap() + @ExperimentalSerializationApi @InternalSerializationApi override val descriptor: SerialDescriptor = buildSerialDescriptor( "TypedSerializer", @@ -32,8 +33,9 @@ open class TypedSerializer( element("value", ContextualSerializer(kClass).descriptor) } + @ExperimentalSerializationApi @InternalSerializationApi - open override fun deserialize(decoder: Decoder): T { + override fun deserialize(decoder: Decoder): T { return decoder.decodeStructure(descriptor) { var type: String? = null lateinit var result: T @@ -56,13 +58,15 @@ open class TypedSerializer( } } + @ExperimentalSerializationApi @InternalSerializationApi protected open fun CompositeEncoder.encode(value: O) { encodeSerializableElement(descriptor, 1, value::class.serializer() as KSerializer, value) } + @ExperimentalSerializationApi @InternalSerializationApi - open override fun serialize(encoder: Encoder, value: T) { + override fun serialize(encoder: Encoder, value: T) { encoder.encodeStructure(descriptor) { val valueSerializer = value::class.serializer() val type = serializers.keys.first { serializers[it] == valueSerializer } @@ -81,6 +85,16 @@ open class TypedSerializer( } } +@InternalSerializationApi +operator fun TypedSerializer.plusAssign(kClass: KClass) { + include(kClass.simpleName!!, kClass.serializer()) +} + +@InternalSerializationApi +operator fun TypedSerializer.minusAssign(kClass: KClass) { + exclude(kClass.simpleName!!) +} + inline fun TypedSerializer( presetSerializers: Map> = emptyMap() ) = TypedSerializer(T::class, presetSerializers)