| 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 | |
List<String> keys; |
| 32 | |
|
| 33 | 0 | public ServicesFilterArrangeByKeys(List<String> keys) { |
| 34 | 0 | this.keys = keys; |
| 35 | 0 | for (int i = 0; i < keys.size(); i++) { |
| 36 | 0 | keys.set(i, keys.get(i).toLowerCase()); |
| 37 | |
} |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
@Override |
| 41 | |
public List<Service> filter(List<Service> services) { |
| 42 | 0 | List<Service> sorted = new ArrayList(services); |
| 43 | 0 | Collections.sort(sorted, new CompareService()); |
| 44 | 0 | return sorted; |
| 45 | |
} |
| 46 | |
|
| 47 | 0 | public class CompareService implements Comparator<Service> { |
| 48 | |
|
| 49 | |
public int compare(Service service1, Service service2) { |
| 50 | 0 | int index1 = keys.indexOf(service1.getKey().toLowerCase()); |
| 51 | 0 | int index2 = keys.indexOf(service2.getKey().toLowerCase()); |
| 52 | 0 | if (index1 < index2) { |
| 53 | 0 | return -1; |
| 54 | |
} |
| 55 | 0 | if (index2 < index1) { |
| 56 | 0 | return +1; |
| 57 | |
} |
| 58 | 0 | return 0; |
| 59 | |
} |
| 60 | |
} |
| 61 | |
} |