mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-25 18:17:15 +00:00
commit
ac68b0b941
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.24.0
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Coroutines`: `1.9.0` -> `1.10.1`
|
||||||
|
* `KSLog`: `1.3.6` -> `1.4.0`
|
||||||
|
* `Compose`: `1.7.1` -> `1.7.3`
|
||||||
|
* `Ktor`: `3.0.2` -> `3.0.3`
|
||||||
|
* `Common`:
|
||||||
|
* Rename `Progress` to more common `Percentage`. `Progress` now is typealias
|
||||||
|
* Fix of `Progress.compareTo` extension
|
||||||
|
|
||||||
## 0.23.2
|
## 0.23.2
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlin.jvm.JvmInline
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains [of1] as main value, where 100% of percentage is when of1 == 1
|
||||||
|
*
|
||||||
|
* @see invoke
|
||||||
|
* @see partOfTotal
|
||||||
|
* @see of100
|
||||||
|
*/
|
||||||
|
@Serializable
|
||||||
|
@JvmInline
|
||||||
|
value class Percentage private constructor(
|
||||||
|
/**
|
||||||
|
* Value of percentage. When it equals to 1, means 100%
|
||||||
|
*/
|
||||||
|
val of1: Double
|
||||||
|
) {
|
||||||
|
/**
|
||||||
|
* Same as [of1], but float (using [Double.toFloat])
|
||||||
|
*/
|
||||||
|
val of1Float
|
||||||
|
get() = of1.toFloat()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represent this percentage as common percentage where 100% is 100%
|
||||||
|
*/
|
||||||
|
val of100
|
||||||
|
get() = of1 * 100
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as [of100], but float (using [Double.toFloat])
|
||||||
|
*/
|
||||||
|
val of100Float
|
||||||
|
get() = of100.toFloat()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as [of100], but int (using [Double.toInt])
|
||||||
|
*/
|
||||||
|
val of100Int
|
||||||
|
get() = of100.toInt()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val rangeOfValues = 0.0 .. 1.0
|
||||||
|
|
||||||
|
val START = Percentage(rangeOfValues.start)
|
||||||
|
val COMPLETED = Percentage(rangeOfValues.endInclusive)
|
||||||
|
|
||||||
|
operator fun invoke(of1: Double) = Percentage(of1.coerceIn(rangeOfValues))
|
||||||
|
operator fun invoke(part: Number, total: Number) = Percentage(
|
||||||
|
part.toDouble() / total.toDouble()
|
||||||
|
)
|
||||||
|
fun of1(of1: Double) = Percentage(of1 = of1)
|
||||||
|
fun of100(of100: Double) = Percentage(of1 = of100 / 100)
|
||||||
|
fun partOfTotal(part: Number, total: Number) = Percentage(part = part, total = total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias Progress = Percentage
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will return [this] [Progress] if [Percentage.of1] in `0 .. 1` range
|
||||||
|
*/
|
||||||
|
fun Progress.ensureStrictOrNull(): Progress? = if (of1 in Percentage.rangeOfValues) this else null
|
||||||
|
/**
|
||||||
|
* Will return [this] [Progress] if [Percentage.of1] in `0 .. 1` range. Otherwise, will throw error
|
||||||
|
* [IllegalArgumentException] due to [require] failure
|
||||||
|
*/
|
||||||
|
fun Progress.ensureStrictOrThrow(): Progress {
|
||||||
|
require(of1 in Percentage.rangeOfValues) {
|
||||||
|
"For strict checks value of percentage must be in ${Percentage.rangeOfValues}, but actual value is $of1"
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
@file:Suppress(
|
||||||
|
"RemoveRedundantCallsOfConversionMethods",
|
||||||
|
"RedundantVisibilityModifier",
|
||||||
|
)
|
||||||
|
|
||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import kotlin.Byte
|
||||||
|
import kotlin.Double
|
||||||
|
import kotlin.Float
|
||||||
|
import kotlin.Int
|
||||||
|
import kotlin.Long
|
||||||
|
import kotlin.Short
|
||||||
|
import kotlin.Suppress
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(other: Percentage): Percentage = Percentage(of1 + other.of1)
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(other: Percentage): Percentage = Percentage(of1 - other.of1)
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(i: Byte): Percentage = Percentage((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(i: Byte): Percentage = Percentage((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.times(i: Byte): Percentage = Percentage((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.div(i: Byte): Percentage = Percentage((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.rem(i: Byte): Percentage = Percentage((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(i: Short): Percentage = Percentage((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(i: Short): Percentage = Percentage((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.times(i: Short): Percentage = Percentage((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.div(i: Short): Percentage = Percentage((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.rem(i: Short): Percentage = Percentage((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(i: Int): Percentage = Percentage((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(i: Int): Percentage = Percentage((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.times(i: Int): Percentage = Percentage((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.div(i: Int): Percentage = Percentage((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.rem(i: Int): Percentage = Percentage((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(i: Long): Percentage = Percentage((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(i: Long): Percentage = Percentage((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.times(i: Long): Percentage = Percentage((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.div(i: Long): Percentage = Percentage((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.rem(i: Long): Percentage = Percentage((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(i: Float): Percentage = Percentage((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(i: Float): Percentage = Percentage((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.times(i: Float): Percentage = Percentage((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.div(i: Float): Percentage = Percentage((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.rem(i: Float): Percentage = Percentage((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.plus(i: Double): Percentage = Percentage((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.minus(i: Double): Percentage = Percentage((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.times(i: Double): Percentage = Percentage((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.div(i: Double): Percentage = Percentage((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.rem(i: Double): Percentage = Percentage((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Percentage.compareTo(other: Percentage): Int = (of1.compareTo(other.of1))
|
@ -1,37 +0,0 @@
|
|||||||
package dev.inmo.micro_utils.common
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlin.jvm.JvmInline
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
@JvmInline
|
|
||||||
value class Progress private constructor(
|
|
||||||
val of1: Double
|
|
||||||
) {
|
|
||||||
val of1Float
|
|
||||||
get() = of1.toFloat()
|
|
||||||
val of100
|
|
||||||
get() = of1 * 100
|
|
||||||
val of100Float
|
|
||||||
get() = of100.toFloat()
|
|
||||||
val of100Int
|
|
||||||
get() = of100.toInt()
|
|
||||||
|
|
||||||
init {
|
|
||||||
require(of1 in rangeOfValues) {
|
|
||||||
"Progress main value should be in $rangeOfValues, but incoming value is $of1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val rangeOfValues = 0.0 .. 1.0
|
|
||||||
|
|
||||||
val START = Progress(rangeOfValues.start)
|
|
||||||
val COMPLETED = Progress(rangeOfValues.endInclusive)
|
|
||||||
|
|
||||||
operator fun invoke(of1: Double) = Progress(of1.coerceIn(rangeOfValues))
|
|
||||||
operator fun invoke(part: Number, total: Number) = Progress(
|
|
||||||
part.toDouble() / total.toDouble()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
@file:Suppress(
|
|
||||||
"RemoveRedundantCallsOfConversionMethods",
|
|
||||||
"RedundantVisibilityModifier",
|
|
||||||
)
|
|
||||||
|
|
||||||
package dev.inmo.micro_utils.common
|
|
||||||
|
|
||||||
import kotlin.Byte
|
|
||||||
import kotlin.Double
|
|
||||||
import kotlin.Float
|
|
||||||
import kotlin.Int
|
|
||||||
import kotlin.Long
|
|
||||||
import kotlin.Short
|
|
||||||
import kotlin.Suppress
|
|
||||||
|
|
||||||
public operator fun Progress.plus(other: Progress): Progress = Progress(of1 + other.of1)
|
|
||||||
|
|
||||||
public operator fun Progress.minus(other: Progress): Progress = Progress(of1 - other.of1)
|
|
||||||
|
|
||||||
public operator fun Progress.plus(i: Byte): Progress = Progress((of1 + i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.minus(i: Byte): Progress = Progress((of1 - i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.times(i: Byte): Progress = Progress((of1 * i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.div(i: Byte): Progress = Progress((of1 / i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.rem(i: Byte): Progress = Progress((of1 % i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.plus(i: Short): Progress = Progress((of1 + i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.minus(i: Short): Progress = Progress((of1 - i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.times(i: Short): Progress = Progress((of1 * i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.div(i: Short): Progress = Progress((of1 / i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.rem(i: Short): Progress = Progress((of1 % i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.plus(i: Int): Progress = Progress((of1 + i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.minus(i: Int): Progress = Progress((of1 - i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.times(i: Int): Progress = Progress((of1 * i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.div(i: Int): Progress = Progress((of1 / i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.rem(i: Int): Progress = Progress((of1 % i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.plus(i: Long): Progress = Progress((of1 + i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.minus(i: Long): Progress = Progress((of1 - i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.times(i: Long): Progress = Progress((of1 * i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.div(i: Long): Progress = Progress((of1 / i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.rem(i: Long): Progress = Progress((of1 % i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.plus(i: Float): Progress = Progress((of1 + i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.minus(i: Float): Progress = Progress((of1 - i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.times(i: Float): Progress = Progress((of1 * i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.div(i: Float): Progress = Progress((of1 / i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.rem(i: Float): Progress = Progress((of1 % i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.plus(i: Double): Progress = Progress((of1 + i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.minus(i: Double): Progress = Progress((of1 - i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.times(i: Double): Progress = Progress((of1 * i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.div(i: Double): Progress = Progress((of1 / i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.rem(i: Double): Progress = Progress((of1 % i).toDouble())
|
|
||||||
|
|
||||||
public operator fun Progress.compareTo(other: Progress): Int = (of1 - other.of1).toInt()
|
|
@ -0,0 +1,29 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class PercentageTests {
|
||||||
|
@Test
|
||||||
|
fun testCompareTo() {
|
||||||
|
val step = 0.01
|
||||||
|
|
||||||
|
var i = Percentage.START.of1
|
||||||
|
while (i <= Percentage.COMPLETED.of1) {
|
||||||
|
val percentageI = Percentage(i)
|
||||||
|
|
||||||
|
var j = Percentage.START.of1
|
||||||
|
while (j <= Percentage.COMPLETED.of1) {
|
||||||
|
val percentageJ = Percentage(j)
|
||||||
|
|
||||||
|
assertEquals(percentageI.of1.compareTo(percentageJ.of1), percentageI.compareTo(percentageJ))
|
||||||
|
assertEquals(percentageI.of1 > percentageJ.of1, percentageI > percentageJ)
|
||||||
|
assertEquals(percentageI.of1 < percentageJ.of1, percentageI < percentageJ)
|
||||||
|
|
||||||
|
j += step
|
||||||
|
}
|
||||||
|
|
||||||
|
i += step
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.23.2
|
version=0.24.0
|
||||||
android_code_version=278
|
android_code_version=279
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
kt = "2.1.0"
|
kt = "2.1.0"
|
||||||
kt-serialization = "1.7.3"
|
kt-serialization = "1.7.3"
|
||||||
kt-coroutines = "1.9.0"
|
kt-coroutines = "1.10.1"
|
||||||
|
|
||||||
kslog = "1.3.6"
|
kslog = "1.4.0"
|
||||||
|
|
||||||
jb-compose = "1.7.1"
|
jb-compose = "1.7.3"
|
||||||
jb-exposed = "0.57.0"
|
jb-exposed = "0.57.0"
|
||||||
jb-dokka = "1.9.20"
|
jb-dokka = "2.0.0"
|
||||||
|
|
||||||
sqlite = "3.47.1.0"
|
sqlite = "3.47.1.0"
|
||||||
|
|
||||||
korlibs = "5.4.0"
|
korlibs = "5.4.0"
|
||||||
uuid = "0.8.4"
|
uuid = "0.8.4"
|
||||||
|
|
||||||
ktor = "3.0.2"
|
ktor = "3.0.3"
|
||||||
|
|
||||||
gh-release = "2.5.2"
|
gh-release = "2.5.2"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user