From 4488f373943a2041c5db3e1ca10f736482351f5f Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 5 Jul 2023 17:47:43 +0200 Subject: [PATCH] Add sugar to Depth --- .../org/pgpainless/wot/dijkstra/sq/Depth.kt | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Depth.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Depth.kt index bfce1e55..8a0551ed 100644 --- a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Depth.kt +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Depth.kt @@ -78,18 +78,11 @@ class Depth private constructor(val limit: Int?) : Comparable { } override fun compareTo(other: Depth): Int { - return if (isUnconstrained()) { - if (other.isUnconstrained()) { - 0 - } else { - 1 - } - } else { - if (other.isUnconstrained()) { - -1 - } else { - limit!!.compareTo(other.limit!!) - } + return when (Pair(isUnconstrained(), other.isUnconstrained())) { + Pair(true, true) -> 0 + Pair(true, false) -> 1 + Pair(false, true) -> -1 + else -> limit!!.compareTo(other.limit!!) } }