Skip to content

Commit

Permalink
refactor: some boolean logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Aug 8, 2024
1 parent 8ec745d commit 2b7a2c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 3 additions & 5 deletions src/main/kotlin/org/janelia/saalfeldlab/fx/actions/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,15 @@ open class Action<E : Event>(val eventType: EventType<E>) {

private fun testChecks(event: E?): Boolean {
return checks.isEmpty() || let {
var valid = true
for ((description, check) in checks) {
valid = valid && check(event)
if (!valid) {
if (!check(event)) {
val startMsg = description?.let { "$it " } ?: ""
val msg ="$startMsg(${check::class.java})"
logger.trace { "Check: $msg did not pass" }
break
return false
}
}
valid
true
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.janelia.saalfeldlab.fx.actions

import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging
import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.Node
import javafx.scene.input.*
import javafx.stage.Window
import org.janelia.saalfeldlab.fx.event.KeyTracker
import java.lang.invoke.MethodHandles
import java.util.function.Consumer


Expand Down Expand Up @@ -192,7 +189,7 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul

/* configure via the callback*/
withAction()
}.also { addAction(it)}
}.also { addAction(it) }
}

/**
Expand Down Expand Up @@ -298,7 +295,7 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul

/* configure based on the callback */
withAction()
}.also { addAction(it)}
}.also { addAction(it) }
}

/**
Expand Down Expand Up @@ -389,7 +386,7 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
try {
action(event)
} catch (e: Exception) {
action.logger.error(e) {"${event.eventType} was valid, but failed" }
action.logger.error(e) { "${event.eventType} was valid, but failed" }
throw e
}
} else {
Expand Down

0 comments on commit 2b7a2c4

Please sign in to comment.