Created
December 17, 2020 11:13
-
-
Save dmarin/af7f14ada34170391a87727d54e2ab8c to your computer and use it in GitHub Desktop.
Compare versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LauncherPredicate @Inject constructor(private val appVersion: String) : Predicate<Launcher> { | |
private val semVerMatcher = "(\\d+)\\.(\\d+)\\.(\\d+)".toRegex() | |
override fun test(launcher: Launcher): Boolean { | |
val version = launcher.minAppVersion | |
if (version.isNullOrEmpty()) { | |
return true | |
} | |
return runCatching { | |
val (launcherMajor, launcherMinor, launcherPatch) = semVerMatcher.find(version)!!.destructured | |
val (appMajor, appMinor, appPatch) = semVerMatcher.find(appVersion)!!.destructured | |
appMajor >= launcherMajor && appMinor >= launcherMinor && appPatch >= launcherPatch | |
}.fold({ it }, { false }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment