From 3dde48612653322f35c227d9375f54edf6efbe0f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Feb 2021 14:31:05 +0600 Subject: [PATCH 1/5] start 0.4.25 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 977e9eaf695..274d25f7737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.25 + ## 0.4.24 * `Versions`: diff --git a/gradle.properties b/gradle.properties index cf79ad930cc..06b74f396c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -44,5 +44,5 @@ dokka_version=1.4.20 # Project data group=dev.inmo -version=0.4.24 -android_code_version=28 +version=0.4.25 +android_code_version=29 From a3cabd7a9eb6d0e1e2d9abf898582e473ad12a0a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Feb 2021 14:43:07 +0600 Subject: [PATCH 2/5] add matrix --- CHANGELOG.md | 3 ++ matrix/build.gradle | 7 +++++ .../dev/inmo/micro_utils/matrix/Matrix.kt | 3 ++ .../inmo/micro_utils/matrix/MatrixBuilder.kt | 10 ++++++ .../kotlin/dev/inmo/micro_utils/matrix/Row.kt | 3 ++ .../dev/inmo/micro_utils/matrix/RowBuilder.kt | 10 ++++++ .../dev/inmo/micro_utils/matrix/Utils.kt | 31 +++++++++++++++++++ matrix/src/main/AndroidManifest.xml | 1 + settings.gradle | 1 + 9 files changed, 69 insertions(+) create mode 100644 matrix/build.gradle create mode 100644 matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt create mode 100644 matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt create mode 100644 matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt create mode 100644 matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt create mode 100644 matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt create mode 100644 matrix/src/main/AndroidManifest.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 274d25f7737..26b64ef203b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.4.25 +* `Matrix`: + * Subproject has been created + ## 0.4.24 * `Versions`: diff --git a/matrix/build.gradle b/matrix/build.gradle new file mode 100644 index 00000000000..7c54502f100 --- /dev/null +++ b/matrix/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt new file mode 100644 index 00000000000..3d757d42cb3 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Matrix.kt @@ -0,0 +1,3 @@ +package dev.inmo.micro_utils.matrix + +typealias Matrix = List> diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt new file mode 100644 index 00000000000..5e7ea1d9d16 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt @@ -0,0 +1,10 @@ +package dev.inmo.micro_utils.matrix + +class MatrixBuilder { + private val mutMatrix: MutableList> = ArrayList() + val matrix: Matrix + get() = mutMatrix + + fun add(t: List) = mutMatrix.add(t) + operator fun plus(t: List) = add(t) +} diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt new file mode 100644 index 00000000000..701457d91b4 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Row.kt @@ -0,0 +1,3 @@ +package dev.inmo.micro_utils.matrix + +typealias Row = List diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt new file mode 100644 index 00000000000..197c63037e7 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt @@ -0,0 +1,10 @@ +package dev.inmo.micro_utils.matrix + +class RowBuilder { + private val mutRow: MutableList = ArrayList() + val row: Row + get() = mutRow + + fun add(t: T) = mutRow.add(t) + operator fun T.unaryPlus() = add(this) +} diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt new file mode 100644 index 00000000000..ea5c444bf55 --- /dev/null +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt @@ -0,0 +1,31 @@ +package dev.inmo.micro_utils.matrix + +fun matrix(block: MatrixBuilder.() -> Unit): Matrix { + return MatrixBuilder().also(block).matrix +} + +fun flatMatrix(block: RowBuilder.() -> Unit): Matrix { + return MatrixBuilder().apply { + row(block) + }.matrix +} + +fun flatMatrix(vararg elements: T): Matrix { + return MatrixBuilder().apply { + row { elements.forEach { +it } } + }.matrix +} + +fun row(block: RowBuilder.() -> Unit): List { + return RowBuilder().also(block).row +} + +fun MatrixBuilder.row(block: RowBuilder.() -> Unit) { + add(RowBuilder().also(block).row) +} + +fun MatrixBuilder.row(vararg elements: T) { + add(elements.toList()) +} + +operator fun RowBuilder.plus(t: T) = add(t) diff --git a/matrix/src/main/AndroidManifest.xml b/matrix/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..90fc16dfe66 --- /dev/null +++ b/matrix/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7b43068aaa5..ea4cd8a08b3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,7 @@ rootProject.name='micro_utils' String[] includes = [ ":common", + ":matrix", ":crypto", ":selector:common", ":pagination:common", From d41c3c2de48a9d4d00ce20b213840e5989be6ec0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Feb 2021 15:05:11 +0600 Subject: [PATCH 3/5] updates in matrix --- .../inmo/micro_utils/matrix/MatrixBuilder.kt | 7 ++- .../matrix/{Utils.kt => MatrixFactories.kt} | 14 ------ .../dev/inmo/micro_utils/matrix/RowBuilder.kt | 5 +++ .../dev/inmo/micro_utils/matrix/SimpleTest.kt | 45 +++++++++++++++++++ 4 files changed, 55 insertions(+), 16 deletions(-) rename matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/{Utils.kt => MatrixFactories.kt} (56%) create mode 100644 matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt index 5e7ea1d9d16..6c5292f47ee 100644 --- a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixBuilder.kt @@ -5,6 +5,9 @@ class MatrixBuilder { val matrix: Matrix get() = mutMatrix - fun add(t: List) = mutMatrix.add(t) - operator fun plus(t: List) = add(t) + fun row(t: List) = mutMatrix.add(t) + operator fun List.unaryPlus() = row(this) } + +fun MatrixBuilder.row(block: RowBuilder.() -> Unit) = +RowBuilder().also(block).row +fun MatrixBuilder.row(vararg elements: T) = +elements.toList() diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixFactories.kt similarity index 56% rename from matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt rename to matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixFactories.kt index ea5c444bf55..045da40645d 100644 --- a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/Utils.kt +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/MatrixFactories.kt @@ -15,17 +15,3 @@ fun flatMatrix(vararg elements: T): Matrix { row { elements.forEach { +it } } }.matrix } - -fun row(block: RowBuilder.() -> Unit): List { - return RowBuilder().also(block).row -} - -fun MatrixBuilder.row(block: RowBuilder.() -> Unit) { - add(RowBuilder().also(block).row) -} - -fun MatrixBuilder.row(vararg elements: T) { - add(elements.toList()) -} - -operator fun RowBuilder.plus(t: T) = add(t) diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt index 197c63037e7..22851e58c30 100644 --- a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt @@ -8,3 +8,8 @@ class RowBuilder { fun add(t: T) = mutRow.add(t) operator fun T.unaryPlus() = add(this) } + +fun row(block: RowBuilder.() -> Unit): List = RowBuilder().also(block).row +fun RowBuilder.column(element: T) = +element +fun RowBuilder.columns(elements: List) = elements.forEach(::column) +fun RowBuilder.columns(vararg elements: T) = elements.forEach(::column) diff --git a/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt b/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt new file mode 100644 index 00000000000..3a8b00e0be1 --- /dev/null +++ b/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt @@ -0,0 +1,45 @@ +package dev.inmo.micro_utils.matrix + +import kotlin.test.Test +import kotlin.test.assertEquals + +class SimpleTest { + @Test + fun simpleTest() { + val expected = listOf( + listOf(1, 2, 3), + listOf(4, 5, 6) + ) + + val fromMatrixWithVarargs = matrix { + row(1, 2, 3) + row(4, 5, 6) + } + + val fromMatrixWithColumnsVarargs = matrix { + row { + columns(1, 2, 3) + } + row { + columns(4, 5, 6) + } + } + + val fromMatrixWithSimpleAdd = matrix { + row { + add(1) + add(2) + add(3) + } + row { + add(4) + add(5) + add(6) + } + } + + assertEquals(expected, fromMatrixWithVarargs) + assertEquals(expected, fromMatrixWithColumnsVarargs) + assertEquals(expected, fromMatrixWithSimpleAdd) + } +} \ No newline at end of file From b120fbd2b11f99bc69f5776f72fe517ae04d3e4f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Feb 2021 15:07:24 +0600 Subject: [PATCH 4/5] remove add and put column method in matrix row builder --- .../kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt index 22851e58c30..f79a71ea2c5 100644 --- a/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt +++ b/matrix/src/commonMain/kotlin/dev/inmo/micro_utils/matrix/RowBuilder.kt @@ -5,11 +5,10 @@ class RowBuilder { val row: Row get() = mutRow - fun add(t: T) = mutRow.add(t) - operator fun T.unaryPlus() = add(this) + fun column(t: T) = mutRow.add(t) + operator fun T.unaryPlus() = column(this) } fun row(block: RowBuilder.() -> Unit): List = RowBuilder().also(block).row -fun RowBuilder.column(element: T) = +element fun RowBuilder.columns(elements: List) = elements.forEach(::column) fun RowBuilder.columns(vararg elements: T) = elements.forEach(::column) From 123b848d74b127da164ec5229d8ec34410880e6c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Feb 2021 15:12:21 +0600 Subject: [PATCH 5/5] update matrix test --- .../kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt b/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt index 3a8b00e0be1..17416d2fe77 100644 --- a/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt +++ b/matrix/src/commonTest/kotlin/dev/inmo/micro_utils/matrix/SimpleTest.kt @@ -27,14 +27,14 @@ class SimpleTest { val fromMatrixWithSimpleAdd = matrix { row { - add(1) - add(2) - add(3) + column(1) + column(2) + column(3) } row { - add(4) - add(5) - add(6) + column(4) + column(5) + column(6) } }