-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUtil.java
65 lines (56 loc) · 1.63 KB
/
Util.java
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
package net.minecraftforge.lex.fffixer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class Util
{
public static interface Indexed
{
public int getIndex();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Iterator sortIndexed(Iterator itr)
{
List list = new ArrayList();
List<Indexed> def_dec = new ArrayList<Indexed>();
int first = -1;
while(itr.hasNext())
{
Object i = itr.next();
//Split off any default variable declarations and sort them.
if (i instanceof Indexed && ((Indexed)i).getIndex() >= 0)
{
if (first == -1) first = list.size();
def_dec.add((Indexed)i);
}
else
{
list.add(i);
}
}
if (def_dec.size() > 0)
{
Collections.sort(def_dec, new Comparator<Indexed>()
{
@Override
public int compare(Indexed o1, Indexed o2)
{
return o1.getIndex() - o2.getIndex();
}
});
list.addAll(first, def_dec);
}
return list.iterator();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T extends Comparable> Iterator<T> sortComparable(Iterator<T> itr)
{
List<T> list = new ArrayList<T>();
while (itr.hasNext())
list.add(itr.next());
Collections.sort(list);
return list.iterator();
}
}