blob: 89c4f167c0b1e948052568c90b2213d9692a5799 (
plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package bjc.dicelang.dicev2;
import bjc.utils.funcutils.ListUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Comparator;
/**
* Die mod which sorts its results.
* @author Ben Culkin
*
*/
public class SortDieMod extends Die {
/**
* Die to sort.
*/
public final Die die;
/**
* Sorter to use.
*/
public Comparator<Long> sorter;
/**
* Create a new sorting die mod.
*
* @param sorter Sorter to use.
* @param die Die to sort.
*/
public SortDieMod(Comparator<Long> sorter, Die die) {
super();
this.sorter = sorter;
this.die = die;
}
@Override
public long[] roll() {
/*
* @NOTE
*
* This is likely quite a bit slower than using Arrays.sort, but
* that only sorts in ascending numeric order. If this ends up
* being a performance issue, add another sort that does that.
*/
List<Long> lst = new ArrayList<>();
for(long val : die.roll()) {
lst.add(val);
}
lst.sort(sorter);
return ListUtils.toPrimitive(lst);
}
@Override
public long rollSingle() {
return die.rollSingle();
}
@Override
public boolean canOptimize() {
return die.canOptimize();
}
@Override
public long optimize() {
return die.optimize();
}
}
|