1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.contract.model.util; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.Comparator; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import org.kuali.student.contract.model.Service; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class ServicesFilterArrangeByKeys implements ServicesFilter |
30 | |
{ |
31 | |
|
32 | |
List<String> keys; |
33 | |
|
34 | |
public ServicesFilterArrangeByKeys (List<String> keys) |
35 | 0 | { |
36 | 0 | this.keys = keys; |
37 | 0 | for (int i = 0; i < keys.size (); i ++) |
38 | |
{ |
39 | 0 | keys.set (i, keys.get (i).toLowerCase ()); |
40 | |
} |
41 | 0 | } |
42 | |
|
43 | |
@Override |
44 | |
public List<Service> filter (List<Service> services) |
45 | |
{ |
46 | 0 | List<Service> sorted = new ArrayList (services); |
47 | 0 | Collections.sort (sorted, new CompareService ()); |
48 | 0 | return sorted; |
49 | |
} |
50 | |
|
51 | 0 | public class CompareService implements Comparator<Service> |
52 | |
{ |
53 | |
|
54 | |
public int compare (Service service1, Service service2) |
55 | |
{ |
56 | 0 | int index1 = keys.indexOf (service1.getKey ().toLowerCase ()); |
57 | 0 | int index2 = keys.indexOf (service2.getKey ().toLowerCase ()); |
58 | 0 | if (index1 < index2) |
59 | |
{ |
60 | 0 | return -1; |
61 | |
} |
62 | 0 | if (index2 < index1) |
63 | |
{ |
64 | 0 | return +1; |
65 | |
} |
66 | 0 | return 0; |
67 | |
} |
68 | |
|
69 | |
} |
70 | |
} |