Skip to content

Commit

Permalink
Fix and simplify side matching code (fixes #54)
Browse files Browse the repository at this point in the history
  • Loading branch information
comp500 committed Jan 17, 2023
1 parent ad951b9 commit 1deed7d
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/main/kotlin/link/infra/packwiz/installer/target/Side.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,29 @@ import cc.ekblad.toml.model.TomlValue
import cc.ekblad.toml.tomlMapper
import com.google.gson.annotations.SerializedName

enum class Side {
enum class Side(sideName: String) {
@SerializedName("client")
CLIENT("client"),
@SerializedName("server")
SERVER("server"),
@SerializedName("both")
@Suppress("unused")
BOTH("both", arrayOf(CLIENT, SERVER));
BOTH("both") {
override fun hasSide(tSide: Side): Boolean {
return true
}
};

private val sideName: String
private val depSides: Array<Side>?

constructor(sideName: String) {
this.sideName = sideName.lowercase()
depSides = null
}

constructor(sideName: String, depSides: Array<Side>) {
init {
this.sideName = sideName.lowercase()
this.depSides = depSides
}

override fun toString() = sideName

fun hasSide(tSide: Side): Boolean {
if (this == tSide) {
return true
}
if (depSides != null) {
for (depSide in depSides) {
if (depSide == tSide) {
return true
}
}
}
return false
open fun hasSide(tSide: Side): Boolean {
return this == tSide || tSide == BOTH
}

companion object {
Expand Down

0 comments on commit 1deed7d

Please sign in to comment.