View Javadoc

1   /*
2    * Copyright 2005-2007 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.lookup.keyvalues;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.kuali.rice.core.util.KeyValue;
26  
27  public abstract class KeyValuesBase implements KeyValuesFinder {
28      public Collection<String> getOptionLabels() {
29      	Collection<String> optionLabels = new ArrayList<String>();
30  
31      	Collection<KeyValue> keyLabels = getKeyValues();
32          for (KeyValue keyLabel : keyLabels) {
33          	optionLabels.add(keyLabel.getValue());
34          }
35          return optionLabels;
36      }
37  
38      public Collection<String> getOptionValues() {
39      	Collection<String> optionValues = new ArrayList<String>();
40  
41      	Collection<KeyValue> keyLabels = getKeyValues();
42          for (KeyValue keyLabel : keyLabels) {
43          	optionValues.add(keyLabel.getKey());
44          }
45          return optionValues;
46      }
47  
48      @Override
49  	public Map<String, String> getKeyLabelMap() {
50          Map<String, String> keyLabelMap = new HashMap<String, String>();
51  
52          List<KeyValue> keyLabels = getKeyValues();
53          for (KeyValue keyLabel : keyLabels) {
54          	keyLabelMap.put(keyLabel.getKey(), keyLabel.getValue());
55          }
56  
57          return keyLabelMap;
58      }
59  
60      @Override
61  	public String getKeyLabel(String key) {
62          Map<String, String> keyLabelMap = getKeyLabelMap();
63  
64          if (keyLabelMap.containsKey(key)) {
65              return keyLabelMap.get(key);
66          }
67          return null;
68      }
69      
70      @Override
71  	public List<KeyValue> getKeyValues(boolean includeActiveOnly){
72      	return Collections.emptyList();
73      }
74      
75  	@Override
76  	public void clearInternalCache() {
77  		// do nothing
78  	}
79  
80  }