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 public class StateValuesFinder extends KeyValuesBase {
32
33 private static List<KeyLabelPair> labels;
34
35
36
37 public List<KeyLabelPair> getKeyValues() {
38 if ( labels == null ) {
39 List<State> baseCodes = KNSServiceLocator.getStateService().findAllStates();
40 List<State> codes = new ArrayList<State>( baseCodes );
41 Collections.sort(codes, new Comparator<State> () {
42 public int compare(State o1, State o2) {
43 return o1.getPostalStateName().compareTo(o2.getPostalStateName());
44 }
45 });
46
47 List<KeyLabelPair> newLabels = new ArrayList<KeyLabelPair>();
48 newLabels.add(new KeyLabelPair("", ""));
49 for (State state : codes) {
50 if(state.isActive()) {
51 newLabels.add(new KeyLabelPair(state.getPostalStateCode(), state.getPostalStateName()));
52 }
53 }
54 labels = newLabels;
55 }
56
57 return labels;
58 }
59
60 @Override
61 public void clearInternalCache() {
62 labels = null;
63 }
64 }