RuneHive-Game
Loading...
Searching...
No Matches
ItemComparator.java
Go to the documentation of this file.
1package com.runehive.game.world.items;
2
3import com.runehive.game.world.items.containers.pricechecker.PriceType;
4
5import java.util.Comparator;
6
7public enum ItemComparator implements Comparator<Item> {
14
15 @Override
16 public int compare(Item first, Item second) {
17 double firstValue = 0;
18 double secondValue = 0;
19
20 if (first == null && second == null) {
21 return 0;
22 }
23
24 if (first == null) {
25 return 1;
26 }
27
28 if (second == null) {
29 return -1;
30 }
31
32 switch (this) {
33
35 firstValue = first.getValue(PriceType.HIGH_ALCH_VALUE);
36 secondValue = second.getValue(PriceType.HIGH_ALCH_VALUE);
37 break;
38
40 firstValue = first.getAmount();
41 secondValue = second.getAmount();
42 break;
43
45 firstValue = first.getId();
46 secondValue = second.getId();
47 break;
48
50 firstValue = first.getWeight();
51 secondValue = second.getWeight();
52 break;
53
55 firstValue = first.getLowAlch();
56 secondValue = second.getLowAlch();
57 break;
58
60 firstValue = first.getValue(PriceType.VALUE);
61 secondValue = second.getValue(PriceType.VALUE);
62 break;
63
64 }
65
66 return Integer.signum((int) (secondValue - firstValue));
67 }
68}
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
int getValue(PriceType type)
Gets the value for this item.
Definition Item.java:98