Coverage Report - org.kuali.rice.kns.bo.options.StateValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
StateValuesFinder
0%
0/14
0%
0/6
2
StateValuesFinder$1
0%
0/2
N/A
2
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * This class...
 30  
  */
 31  0
 public class StateValuesFinder extends KeyValuesBase {
 32  
 
 33  
         private static List<KeyLabelPair> labels;
 34  
     /*
 35  
      * @see org.kuali.keyvalues.KeyValuesFinder#getKeyValues()
 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  
 }