From 1d9f5e886ce1841c2915c8b79570acf5d1fcbbfd Mon Sep 17 00:00:00 2001 From: Attacktive Date: Fri, 24 May 2024 17:59:23 +0900 Subject: [PATCH] refactor: remove unused property and function https://github.com/Attacktive/troubleshooter-editor-back-end/issues/150 --- .../domain/common/Properties.kt | 3 +-- .../domain/roster/RosterObject.kt | 3 --- .../extension/Extensions.kt | 20 ++----------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/common/Properties.kt b/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/common/Properties.kt index 8642bfb..af86eb9 100644 --- a/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/common/Properties.kt +++ b/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/common/Properties.kt @@ -11,7 +11,6 @@ open class Properties(private val list: List = mutableListOf()) { fun containsKey(key: String) = keys().contains(key) fun containsKeyThat(predicate: Predicate) = keys().any { predicate.test(it) } - fun forEach(action: (Property) -> Unit) = list.forEach(action) fun toMap() = list.associate { it.key to it.value } fun diff(those: Properties): Properties { @@ -45,7 +44,7 @@ open class Properties(private val list: List = mutableListOf()) { } fun applyPropertyChanges(diffResult: IDiffResult, propertyMasterLookup: Map) { - forEach { property -> + for (property in list) { val propertyIndex = propertyMasterLookup[property.key] if (propertyIndex == null) { logger.warn("Failed to find item property master index for \"${property.key}\"; ignoring. 😞") diff --git a/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/roster/RosterObject.kt b/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/roster/RosterObject.kt index 358fc6e..d7bc34b 100644 --- a/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/roster/RosterObject.kt +++ b/src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/roster/RosterObject.kt @@ -5,7 +5,6 @@ import com.github.attacktive.troubleshootereditor.domain.roster.table.RosterProp import com.github.attacktive.troubleshootereditor.domain.roster.table.RosterPropertyMaster import com.github.attacktive.troubleshootereditor.domain.roster.table.Rosters import com.github.attacktive.troubleshootereditor.extension.getDiffResults -import com.github.attacktive.troubleshootereditor.extension.logger import com.github.attacktive.troubleshootereditor.extension.toProperties import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.StdOutSqlLogger @@ -15,8 +14,6 @@ import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.update object RosterObject { - private val logger by logger() - fun selectRosters(url: String): List { Database.connect(url) diff --git a/src/main/kotlin/com/github/attacktive/troubleshootereditor/extension/Extensions.kt b/src/main/kotlin/com/github/attacktive/troubleshootereditor/extension/Extensions.kt index bf3c6a4..bee899c 100644 --- a/src/main/kotlin/com/github/attacktive/troubleshootereditor/extension/Extensions.kt +++ b/src/main/kotlin/com/github/attacktive/troubleshootereditor/extension/Extensions.kt @@ -1,10 +1,7 @@ package com.github.attacktive.troubleshootereditor.extension import java.io.File -import java.util.function.Supplier import kotlin.reflect.full.companionObject -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue import com.github.attacktive.troubleshootereditor.domain.common.Diffable import com.github.attacktive.troubleshootereditor.domain.common.Identifiable import com.github.attacktive.troubleshootereditor.domain.common.Properties @@ -14,25 +11,12 @@ import org.slf4j.LoggerFactory fun Iterable.toProperties() = Properties(toMutableList()) -inline infix fun , V> ((E) -> V).findBy(value: V): E { - return findBy(value) { IllegalArgumentException("No enum constant ${javaClass.canonicalName}.$value.") } -} - -inline fun , V> ((E) -> V).findBy(value: V, throwableSupplier: Supplier): E { - return enumValues().firstOrNull { this(it) == value } ?: throw throwableSupplier.get() -} - -inline infix fun , V> ((E) -> V).findByOrNull(value: V): E? { +inline infix fun , V> ((E) -> V).findByOrNull(value: V): E? { return enumValues().firstOrNull { this(it) == value } } fun File.getJdbcUrl() = "jdbc:sqlite:${absolutePath}" -fun String.deserializeAsStringToStringMap(): Map { - val objectMapper = jacksonObjectMapper() - return objectMapper.readValue(this) -} - fun > Collection.findById(id: I): T? = asSequence().find { it.getId() == id } fun , D> Collection.getDiffResults(those: Collection): List { @@ -58,6 +42,6 @@ fun T.logger(): Lazy { /** * Unwraps companion class to enclosing class given a Java Class */ -fun unwrapCompanionClass(ofClass: Class): Class<*> { +fun unwrapCompanionClass(ofClass: Class): Class<*> { return ofClass.enclosingClass?.takeIf { it.kotlin.companionObject?.java == ofClass } ?: ofClass }