From 956cbab1f7f61406b6a85ba000f12f02f66eb02e Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 30 Oct 2024 17:35:53 +0100 Subject: [PATCH] improve 'by station' potion order sorting (#80) --- .../masteringmixology/PotionComparators.java | 24 +++++++++++++++++++ .../masteringmixology/PotionOrderSorting.java | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/work/fking/masteringmixology/PotionComparators.java diff --git a/src/main/java/work/fking/masteringmixology/PotionComparators.java b/src/main/java/work/fking/masteringmixology/PotionComparators.java new file mode 100644 index 0000000..b14df1f --- /dev/null +++ b/src/main/java/work/fking/masteringmixology/PotionComparators.java @@ -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 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()); + } +} diff --git a/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java b/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java index e079b35..d0a6ad2 100644 --- a/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java +++ b/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java @@ -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 comparator;