Skip to content

Commit

Permalink
refactor: remove unused property and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Attacktive committed May 24, 2024
1 parent 8eb87af commit e3d11fc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ open class Properties(private val list: List<Property> = mutableListOf()) {
fun containsKey(key: String) = keys().contains(key)
fun containsKeyThat(predicate: Predicate<String>) = 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 {
Expand Down Expand Up @@ -45,7 +44,7 @@ open class Properties(private val list: List<Property> = mutableListOf()) {
}

fun <T> applyPropertyChanges(diffResult: IDiffResult<T>, propertyMasterLookup: Map<String, Int>) {
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. 😞")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Roster> {
Database.connect(url)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,25 +11,12 @@ import org.slf4j.LoggerFactory

fun Iterable<Property>.toProperties() = Properties(toMutableList())

inline infix fun <reified E : Enum<E>, V> ((E) -> V).findBy(value: V): E {
return findBy(value) { IllegalArgumentException("No enum constant ${javaClass.canonicalName}.$value.") }
}

inline fun <reified E : Enum<E>, V> ((E) -> V).findBy(value: V, throwableSupplier: Supplier<Throwable>): E {
return enumValues<E>().firstOrNull { this(it) == value } ?: throw throwableSupplier.get()
}

inline infix fun <reified E : Enum<E>, V> ((E) -> V).findByOrNull(value: V): E? {
inline infix fun <reified E: Enum<E>, V> ((E) -> V).findByOrNull(value: V): E? {
return enumValues<E>().firstOrNull { this(it) == value }
}

fun File.getJdbcUrl() = "jdbc:sqlite:${absolutePath}"

fun String.deserializeAsStringToStringMap(): Map<String, String> {
val objectMapper = jacksonObjectMapper()
return objectMapper.readValue(this)
}

fun <I, T: Identifiable<I>> Collection<T>.findById(id: I): T? = asSequence().find { it.getId() == id }

fun <I, T: Diffable<T, I, D>, D> Collection<T>.getDiffResults(those: Collection<T>): List<D> {
Expand All @@ -58,6 +42,6 @@ fun <T: Any> T.logger(): Lazy<Logger> {
/**
* Unwraps companion class to enclosing class given a Java Class
*/
fun <T : Any> unwrapCompanionClass(ofClass: Class<T>): Class<*> {
fun <T: Any> unwrapCompanionClass(ofClass: Class<T>): Class<*> {
return ofClass.enclosingClass?.takeIf { it.kotlin.companionObject?.java == ofClass } ?: ofClass
}

0 comments on commit e3d11fc

Please sign in to comment.