forked from hex-agon/mastering-mixology
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve 'by station' potion order sorting (hex-agon#80)
- Loading branch information
1 parent
a5391ca
commit 956cbab
Showing
2 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/work/fking/masteringmixology/PotionComparators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters