Style[launcher]: simplify rank check

This commit is contained in:
artdeell 2024-07-06 21:47:57 +03:00 committed by Maksim Belov
parent ed048fb4cb
commit 045018f8e0
2 changed files with 10 additions and 14 deletions

View File

@ -93,13 +93,11 @@ public class NewJREUtil {
// 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<Runtime> nearestInstalledRuntime = getNearestInstalledRuntime(gameRequiredVersion);
MathUtils.RankedValue<InternalRuntime> 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

View File

@ -57,21 +57,19 @@ public class MathUtils {
}
/**
* 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 <T> Type of object 1
* @param <Y> Type of object 2
* @param <T> Type of objects
*/
public static <T,Y> Object multiTypeObjectMin(T object1, Y object2, ValueProvider<T> valueProvider1, ValueProvider<Y> valueProvider2) {
public static <T> T objectMin(T object1, T object2, ValueProvider<T> 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 {