Add Loot Record Comparator enum for sorting LootRecords
Signed-off-by: PKLite <stonewall@pklite.xyz>
This commit is contained in:
@@ -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<LootTrackerRecord>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user