1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.bo.options; |
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.rice.core.util.KeyLabelPair; |
24 | |
import org.kuali.rice.kns.bo.State; |
25 | |
import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase; |
26 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class StateValuesFinder extends KeyValuesBase { |
32 | |
|
33 | |
private static List<KeyLabelPair> labels; |
34 | |
|
35 | |
|
36 | |
|
37 | |
public List<KeyLabelPair> getKeyValues() { |
38 | 0 | if ( labels == null ) { |
39 | 0 | List<State> baseCodes = KNSServiceLocator.getStateService().findAllStates(); |
40 | 0 | List<State> codes = new ArrayList<State>( baseCodes ); |
41 | 0 | Collections.sort(codes, new Comparator<State> () { |
42 | |
public int compare(State o1, State o2) { |
43 | 0 | return o1.getPostalStateName().compareTo(o2.getPostalStateName()); |
44 | |
} |
45 | |
}); |
46 | |
|
47 | 0 | List<KeyLabelPair> newLabels = new ArrayList<KeyLabelPair>(); |
48 | 0 | newLabels.add(new KeyLabelPair("", "")); |
49 | 0 | for (State state : codes) { |
50 | 0 | if(state.isActive()) { |
51 | 0 | newLabels.add(new KeyLabelPair(state.getPostalStateCode(), state.getPostalStateName())); |
52 | |
} |
53 | |
} |
54 | 0 | labels = newLabels; |
55 | |
} |
56 | |
|
57 | 0 | return labels; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public void clearInternalCache() { |
62 | 0 | labels = null; |
63 | 0 | } |
64 | |
} |