1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.location.framework.country;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
22 import org.kuali.rice.location.api.country.Country;
23
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.List;
28
29
30
31
32
33
34 public abstract class AbstractCountryValuesFinderBase extends KeyValuesBase {
35
36
37
38
39
40
41
42 protected abstract List<Country> retrieveCountriesForValuesFinder();
43
44 @Override
45 public List<KeyValue> getKeyValues() {
46 List<Country> boList = new ArrayList<Country>(retrieveCountriesForValuesFinder());
47 List<KeyValue> labels = new ArrayList<KeyValue>(boList.size() + 1);
48
49 labels.add(new ConcreteKeyValue("", ""));
50
51 Collections.sort(boList, new Comparator<Country>() {
52 @Override
53 public int compare(Country o1, Country o2) {
54
55
56 String sortValue1 = StringUtils.trim(StringUtils.removeStart(o1.getName(), "*"));
57 String sortValue2 = StringUtils.trim(StringUtils.removeStart(o2.getName(), "*"));
58 return sortValue1.compareToIgnoreCase(sortValue2);
59 }
60
61 });
62
63 for (Country country : boList) {
64 if (country.isActive()) {
65 labels.add(new ConcreteKeyValue(country.getCode(), country.getName()));
66 }
67 }
68 return labels;
69 }
70 }