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