1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.location.framework.state; |
17 | |
|
18 | |
import org.kuali.rice.core.api.util.ConcreteKeyValue; |
19 | |
import org.kuali.rice.core.api.util.KeyValue; |
20 | |
import org.kuali.rice.krad.keyvalues.KeyValuesBase; |
21 | |
import org.kuali.rice.location.api.services.LocationApiServiceLocator; |
22 | |
import org.kuali.rice.location.api.state.State; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collections; |
26 | |
import java.util.Comparator; |
27 | |
import java.util.List; |
28 | |
|
29 | 0 | public class StateValuesFinder extends KeyValuesBase { |
30 | |
|
31 | 0 | private String countryCode = "US"; |
32 | |
|
33 | |
@Override |
34 | |
public List<KeyValue> getKeyValues() { |
35 | 0 | List<KeyValue> labels = new ArrayList<KeyValue>(); |
36 | 0 | List<State> baseCodes = LocationApiServiceLocator.getStateService().findAllStatesInCountry(countryCode); |
37 | 0 | List<State> codes = new ArrayList<State>( baseCodes ); |
38 | 0 | Collections.sort(codes, new Comparator<State> () { |
39 | |
@Override |
40 | |
public int compare(State o1, State o2) { |
41 | 0 | return o1.getName().compareTo(o2.getName()); |
42 | |
} |
43 | |
}); |
44 | |
|
45 | 0 | List<KeyValue> newLabels = new ArrayList<KeyValue>(); |
46 | 0 | newLabels.add(new ConcreteKeyValue("", "")); |
47 | 0 | for (State state : codes) { |
48 | 0 | if(state.isActive()) { |
49 | 0 | newLabels.add(new ConcreteKeyValue(state.getCode(), state.getName())); |
50 | |
} |
51 | |
} |
52 | 0 | labels = newLabels; |
53 | |
|
54 | 0 | return labels; |
55 | |
} |
56 | |
|
57 | |
public void setCountryCode(String countryCode) { |
58 | 0 | this.countryCode = countryCode; |
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
@Override |
63 | |
public void clearInternalCache() { |
64 | 0 | } |
65 | |
} |