From e3aa3fd2fd8a43786f480c5cff84a2c514bbc9b8 Mon Sep 17 00:00:00 2001 From: PKLite Date: Sun, 9 Jun 2019 00:55:11 -0400 Subject: [PATCH] Add Loot Record Comparator enum for sorting LootRecords Signed-off-by: PKLite --- .../loottracker/LootRecordSortType.java | 39 +++++++++++++++++++ .../plugins/loottracker/LootTrackerBox.java | 1 + 2 files changed, 40 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java new file mode 100644 index 0000000000..6efd941100 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java @@ -0,0 +1,39 @@ +package net.runelite.client.plugins.loottracker; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.stream.IntStream; + +/** + * + */ +public enum LootRecordSortType implements Comparator +{ + TIMESTAMP + { + @Override + public int compare(LootTrackerRecord o1, LootTrackerRecord o2) + { + return Math.toIntExact(o1.getTimestamp() - o2.getTimestamp()); + } + }, + TOTAL_VALUE + { + @Override + public int compare(LootTrackerRecord o1, LootTrackerRecord o2) + { + int sum = Arrays.stream(o1.getItems()).flatMapToInt(lootTrackerItem -> + IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); + return sum - Arrays.stream(o2.getItems()).flatMapToInt(lootTrackerItem -> + IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); + } + }, + ITEM_COUNT + { + @Override + public int compare(LootTrackerRecord o1, LootTrackerRecord o2) + { + return o1.getItems().length - o2.getItems().length; + } + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java index 2022e5f72c..a05890f57a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java @@ -32,6 +32,7 @@ import java.awt.GridLayout; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; import javax.annotation.Nullable;