From 045018f8e08bb8199086fe7c8e8315c3f1da911c Mon Sep 17 00:00:00 2001 From: artdeell Date: Sat, 6 Jul 2024 21:47:57 +0300 Subject: [PATCH] Style[launcher]: simplify rank check --- .../main/java/net/kdt/pojavlaunch/NewJREUtil.java | 10 ++++------ .../java/net/kdt/pojavlaunch/utils/MathUtils.java | 14 ++++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java index a0df3f7c52..3b7f7c7580 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java @@ -93,13 +93,11 @@ public static boolean installNewJreIfNeeded(Activity activity, JMinecraftVersion // If the runtime version selected by the user is not appropriate for this version (which means the game won't run at all) // automatically pick from either an already installed runtime, or a runtime packed with the launcher - MathUtils.RankedValue nearestInstalledRuntime = getNearestInstalledRuntime(gameRequiredVersion); - MathUtils.RankedValue nearestInternalRuntime = getNearestInternalRuntime(gameRequiredVersion); + MathUtils.RankedValue nearestInstalledRuntime = getNearestInstalledRuntime(gameRequiredVersion); + MathUtils.RankedValue nearestInternalRuntime = getNearestInternalRuntime(gameRequiredVersion); - MathUtils.RankedValue selectedRankedRuntime = (MathUtils.RankedValue) MathUtils.multiTypeObjectMin( - nearestInternalRuntime, nearestInstalledRuntime, - (v1)->v1.rank, - (v2)->v2.rank + MathUtils.RankedValue selectedRankedRuntime = MathUtils.objectMin( + nearestInternalRuntime, nearestInstalledRuntime, (value)->value.rank ); // No possible selections diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java index b00b492570..f3a49f64ae 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java @@ -57,21 +57,19 @@ public RankedValue(T value, int rank) { } /** - * Out of two objects with different types, select one with the lowest value. + * Out of two objects, select one with the lowest value. * @param object1 Object 1 for comparsion * @param object2 Object 2 for comparsion - * @param valueProvider1 Value provider for object 1 - * @param valueProvider2 Value provider for object 2 + * @param valueProvider Value provider for the objects * @return If value of object 1 is lower than or equal to object 2, returns object 1 * Otherwise, returns object 2 - * @param Type of object 1 - * @param Type of object 2 + * @param Type of objects */ - public static Object multiTypeObjectMin(T object1, Y object2, ValueProvider valueProvider1, ValueProvider valueProvider2) { + public static T objectMin(T object1, T object2, ValueProvider valueProvider) { if(object1 == null) return object2; if(object2 == null) return object1; - int value1 = valueProvider1.getValue(object1); - int value2 = valueProvider2.getValue(object2); + int value1 = valueProvider.getValue(object1); + int value2 = valueProvider.getValue(object2); if(value1 <= value2) { return object1; } else {