Skip to content

Commit

Permalink
improve 'by station' potion order sorting (hex-agon#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSoapTurtle committed Oct 31, 2024
1 parent a5391ca commit 956cbab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/work/fking/masteringmixology/PotionComparators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package work.fking.masteringmixology;

import java.util.Comparator;

public class PotionComparators {

// Sort by modifier, in the order CRYSTALISED > HOMOGENOUS > CONCENTRATED
// And then by PotionType name alphabetically
public static Comparator<PotionOrder> byStation() {
return Comparator.comparingInt((PotionOrder order) -> {
switch (order.potionModifier()) {
case CRYSTALISED:
return 0;
case HOMOGENOUS:
return 1;
case CONCENTRATED:
return 2;
default:
return Integer.MAX_VALUE;
}
})
.thenComparing(order -> order.potionType().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public enum PotionOrderSorting {
VANILLA("Vanilla (random)", null),
BY_STATION("By station", Comparator.comparing(order -> order.potionModifier().ordinal()));
BY_STATION("By station", PotionComparators.byStation());

private final String name;
private final Comparator<PotionOrder> comparator;
Expand Down

0 comments on commit 956cbab

Please sign in to comment.