Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Fix: critical infrastructure detection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFruxz committed Jan 2, 2022
1 parent 520b585 commit f3c61c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.jet.jvm.interchange

import de.jet.jvm.tool.smart.positioning.Address
import de.jet.jvm.tree.TreeBranch
import de.jet.jvm.tree.TreeBranchType

/**
* This class defines a branch of the console interchange.
Expand All @@ -25,7 +24,7 @@ class ConsoleInterchangeBranch(
* @author Fruxz
*/
fun getBestMatchFromCommandInput(commandInput: String): ConsoleInterchangeBranch? {
return getBestMatchFromPath(Address(commandInput.replace(" ", "/")))
return getBestMatchFromPath(Address.address(commandInput.replace(" ", "/")))
}

/**
Expand All @@ -37,7 +36,7 @@ class ConsoleInterchangeBranch(
* @author Fruxz
*/
fun getBestMatchFromCommandInputWithParameters(commandInput: String): Pair<ConsoleInterchangeBranch?, String> {
val (branch, remaining) = getBestMatchFromPathWithRemaining(Address(commandInput.replace(" ", "/")))
val (branch, remaining) = getBestMatchFromPathWithRemaining(Address.address(commandInput.replace(" ", "/")))
return Pair(branch, remaining.addressString.replace("/", " ").removePrefix(" "))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.jet.jvm.interchange

import de.jet.jvm.extension.input.buildConsoleInterchange
import de.jet.jvm.extension.switchResult

/**
Expand Down Expand Up @@ -27,14 +28,14 @@ data class ConsoleInterchangeConfiguration(
fun executeCommand(input: String): Boolean {

fun executeBase(input: String): Boolean {
interchanges.forEach {
it.getBestMatchFromCommandInputWithParameters(input).let { result ->
result.first.let { branch ->
if (branch != null) {
branch.content?.let { content ->
content.invoke(result.second)
return true
}
buildConsoleInterchange("") {
subBranches = interchanges
}.getBestMatchFromCommandInputWithParameters(input).let { result ->
result.first.let { branch ->
if (branch != null) {
branch.content?.let { content ->
content.invoke(result.second)
return true
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions JET-JVM/src/main/kotlin/de/jet/jvm/tree/TreeBranch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ open class TreeBranch<SUBBRANCH : TreeBranch<SUBBRANCH, CONTENT, BRANCH_TYPE>, C
open var content: CONTENT,
) : Identifiable<TreeBranch<SUBBRANCH, CONTENT, BRANCH_TYPE>>, Pathed<TreeBranch<SUBBRANCH, CONTENT, BRANCH_TYPE>> {

init {
subBranches = subBranches.distinctBy { path }
}

/**
* This function replaces the current [content] of the branch with the given new [content].
* @param content the new content of the branch
Expand All @@ -56,7 +52,7 @@ open class TreeBranch<SUBBRANCH : TreeBranch<SUBBRANCH, CONTENT, BRANCH_TYPE>, C
* @since 1.0
*/
fun allKnownBranches(): List<SUBBRANCH> {
return (subBranches.flatMap { it.allKnownBranches() } + this.forceCast<SUBBRANCH>())
return ((subBranches.flatMap { it.allKnownBranches() } + this.forceCast<SUBBRANCH>()).distinctBy { it.path })
}

/**
Expand All @@ -69,7 +65,7 @@ open class TreeBranch<SUBBRANCH : TreeBranch<SUBBRANCH, CONTENT, BRANCH_TYPE>, C
fun getBestMatchFromPath(path: Address<TreeBranch<SUBBRANCH, CONTENT, BRANCH_TYPE>>): SUBBRANCH? {
return allKnownBranches()
.filter { path.addressString.startsWith(it.path.addressString) }
.maxByOrNull { it.addressString.length }
.maxByOrNull { obj -> obj.address.let { address -> return@let address.addressString.split(address.divider) }.let { split -> split.size + split.last().length } }
}

/**
Expand Down

0 comments on commit f3c61c3

Please sign in to comment.