SortableValue.java
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.util;
/**
* Struct which contains a mapping of a priority value to another object, used
* for sorting items using the native functionality in TreeMap and TreeSet.
*
* @author Adam Mummery-Smith
*/
public class SortableValue<T> implements Comparable<SortableValue<?>>
{
private final int priority;
private final int order;
private final T value;
public SortableValue(int priority, int order, T value)
{
this.priority = priority;
this.order = order;
this.value = value;
}
public int getPriority()
{
return this.priority;
}
public int getOrder()
{
return this.order;
}
public T getValue()
{
return this.value;
}
@Override
public int compareTo(SortableValue<?> other)
{
if (other == null) return 0;
if (other.priority == this.priority) return this.order - other.order;
return (this.priority - other.priority);
}
}