Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
gradle_build:
strategy:
matrix:
os: [ macos-13, macos-14, windows-2022 ]
os: [ macos-15-intel, macos-15, windows-2022 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
strategy:
matrix:
configuration: [
{ runner: "macos-13", path: "build/dist/*" },
{ runner: "macos-14", path: "build/dist/*" },
{ runner: "macos-15-intel", path: "build/dist/*" },
{ runner: "macos-15", path: "build/dist/*" },
{ runner: "windows-2022", path: "build/dist/*" }
]
runs-on: ${{ matrix.configuration.runner }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
strategy:
matrix:
configuration: [
{ runner: "macos-13", path: "build/dist" },
{ runner: "macos-14", path: "build/dist" },
{ runner: "macos-15-intel", path: "build/dist" },
{ runner: "macos-15", path: "build/dist" },
{ runner: "windows-2022", path: "build/dist" }
]
runs-on: ${{ matrix.configuration.runner }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

## Сборка дистрибутива

Задача `:jpackage` в `build.gradle` Запускает утилиту [**jpackage
**](https://docs.oracle.com/en/java/javase/21/docs/specs/man/jpackage.html).
Задача `:jpackage` в `build.gradle` Запускает утилиту
[jpackage](https://docs.oracle.com/en/java/javase/21/docs/specs/man/jpackage.html).

```shell
./gradlew jpackage
Expand Down
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
id "org.openjfx.javafxplugin" version "0.1.0"
id "org.jetbrains.dokka" version "2.0.0"
id "me.champeau.jmh" version "0.7.3"
}

group "ru.nucodelabs"
Expand Down Expand Up @@ -100,6 +101,7 @@ dependencies {
"$projectDir/lib/${System.mapLibraryName("MathVES")}"
)

/* Slf4j Logging */
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation project(":app-logback-appender")
Expand All @@ -114,11 +116,8 @@ dependencies {
implementation "org.codehaus.groovy:groovy-jsr223:3.0.25"

implementation group: "com.fasterxml.jackson.core", name: "jackson-databind", version: jacksonVersion
implementation group: "org.apache.commons", name: "commons-math3", version: "3.6.1"

implementation group: "com.google.inject", name: "guice", version: guiceVersion
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion"
implementation "org.apache.commons:commons-collections4:4.4"

/* Math Libraries */
implementation "org.glassfish.expressly:expressly:5.0.0"
Expand All @@ -127,13 +126,16 @@ dependencies {
implementation "org.bytedeco:javacpp:1.5.12:$platform"
implementation "org.bytedeco:arpack-ng:3.9.1-1.5.12:$platform"
implementation "org.bytedeco:arpack-ng:3.9.1-1.5.12"
implementation group: "org.apache.commons", name: "commons-math3", version: "3.6.1"

/* Test Dependencies */
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:$mapstructVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinTestVersion"
testImplementation "org.openjfx:javafx:${javafx.version}"

jmh "org.apache.commons:commons-lang3:3.18.0"
}

/* Setup Runtime */
Expand Down Expand Up @@ -164,7 +166,7 @@ tasks.register("cleanRunDir", Delete) {
delete fileTree(runDir) { exclude "err-trace*.txt" }
}

tasks.withType(JavaExec).configureEach {
run {
dependsOn copyClrToRunDir, copyDataToRunDir, copyLibsToRunDir
jvmArgs = moduleExportsJvmArgs
systemProperty("app.gem.log.stdout", true)
Expand Down
35 changes: 35 additions & 0 deletions common-utils/src/main/kotlin/ru/nucodelabs/util/Equals.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.nucodelabs.util

import java.util.Objects
import kotlin.reflect.KClass

class Equals<T : Any>(
val thisRef: T,
val other: Any?
) {
var isEqual = thisRef === other || other != null && thisRef::class == other::class

inline fun by(getter: (o: T) -> Any?): Equals<T> {
if (!isEqual) return this
@Suppress("unchecked_cast")
isEqual = isEqual && getter(thisRef) == getter(other as T)
return this
}

inline fun and(condition: (it: T, other: T) -> Boolean): Equals<T> {
if (!isEqual) return this
@Suppress("unchecked_cast")
isEqual = isEqual && condition(thisRef, other as T)
return this
}

inline fun and(condition: () -> Boolean): Equals<T> {
if (!isEqual) return this
isEqual = isEqual && condition()
return this
}
}

fun hash(vararg values: Any?): Int {
return Objects.hash(*values)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.nucodelabs.util.std
package ru.nucodelabs.util

fun <T> MutableList<T>.swap(index1: Int, index2: Int) {
val tmp = this[index1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.nucodelabs.util.std
package ru.nucodelabs.util

import java.text.DecimalFormat
import kotlin.math.pow
Expand Down
50 changes: 50 additions & 0 deletions common-utils/src/main/kotlin/ru/nucodelabs/util/Result.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ru.nucodelabs.util

sealed interface Result<TYPE, ERROR>

@JvmInline
value class Ok<T, E>(val value: T) : Result<T, E>

@JvmInline
value class Err<T, E>(val error: E) : Result<T, E>

fun <T, E> T.toOkResult(): Result<T, E> = Ok(this)
fun <T, E> E.toErrorResult(): Result<T, E> = Err(this)

@Suppress("unused")
inline fun <T, E> Result<T, E>.okOrThrow(
mapError: (E) -> Throwable = { IllegalStateException(it.toString()) }
): T {
return when (this) {
is Ok -> value
is Err -> throw mapError(error)
}
}

@Suppress("unused")
fun <T, E> Result<T, E>.okOrNull(): T? {
return when (this) {
is Ok -> value
is Err -> null
}
}

@Suppress("unused")
fun <T, E> Result<T, E>.errorOrNull(): E? {
return when (this) {
is Err -> error
is Ok -> null
}
}

@Suppress("unused")
inline fun <T, E> Result<T, E>.ifError(action: (E) -> Unit): Result<T, E> {
if (this is Err) action(error)
return this
}

@Suppress("unused")
inline fun <T, E> Result<T, E>.ifOk(action: (T) -> Unit): Result<T, E> {
if (this is Ok) action(value)
return this
}
9 changes: 9 additions & 0 deletions common-utils/src/main/kotlin/ru/nucodelabs/util/Validation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.nucodelabs.util

/**
* Return null if valid else error object
*/
inline fun <T> validate(condition: Boolean, lazyError: () -> T): T? {
if (condition) return null
return lazyError()
}
81 changes: 81 additions & 0 deletions common-utils/src/test/kotlin/ru/nucodelabs/util/EqualsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ru.nucodelabs.util

import org.junit.jupiter.api.Test

class EqualsTest {
class Some(
val a: Int,
val b: String,
val c: Double,
val d: List<String>
)

var objA: Some = Some(1, "12345", 1234.5678, listOf("Some", "String", "Content"))
var objB: Some = Some(1, "12345", 1234.5678, listOf("Some", "String", "Content"))

@Test
fun isEqual() {
assert(objA !== objB)
assert(objA != objB)
val result = Equals(objA, objB)
.by { it.a }
.by { it.b }
.by { it.c }
.by { it.d }
.isEqual
assert(result)
}

@Test
fun isEqual_same() {
val result = Equals(objA, objB)
.by { it.a }
.by { it.b }
.by { it.c }
.by { it.d }
.isEqual
assert(result)
}

@Test
fun isEqual_not() {
objB = Some(2, "123", 123.32, emptyList())
assert(objA !== objB)
assert(objA != objB)
val result = Equals(objA, objB)
.by { it.a }
.by { it.b }
.by { it.c }
.by { it.d }
.isEqual
assert(!result)
}

@Test
fun and() {
val a = doubleArrayOf(.1, .2, .3)
val b = doubleArrayOf(.1, .2, .3)
val result = Equals(objA, objB)
.by { it.a }
.by { it.b }
.by { it.c }
.by { it.d }
.and { a contentEquals b }
.isEqual
assert(result)
}

@Test
fun and_false() {
val a = doubleArrayOf(.1, .2, .3)
val b = doubleArrayOf(.1, .2, .3, .4)
val result = Equals(objA, objB)
.by { it.a }
.by { it.b }
.by { it.c }
.by { it.d }
.and { a contentEquals b }
.isEqual
assert(!result)
}
}
Loading
Loading