Skip to content

Commit

Permalink
Style[launcher]: simplify rank check
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Jul 9, 2024
1 parent ed048fb commit 045018f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 {
Expand Down

0 comments on commit 045018f

Please sign in to comment.