View Javadoc
1   /**
2    * Copyright 2005-2016 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.krad.keyvalues;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.kuali.rice.core.api.util.KeyValue;
27  
28  /**
29   * Abstract base implementation of {@link KeyValuesFinder}
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public abstract class KeyValuesBase implements KeyValuesFinder, Serializable {
34  
35      public Collection<String> getOptionLabels() {
36      	Collection<String> optionLabels = new ArrayList<String>();
37  
38      	Collection<KeyValue> keyLabels = getKeyValues();
39          for (KeyValue keyLabel : keyLabels) {
40          	optionLabels.add(keyLabel.getValue());
41          }
42          return optionLabels;
43      }
44  
45      public Collection<String> getOptionValues() {
46      	Collection<String> optionValues = new ArrayList<String>();
47  
48      	Collection<KeyValue> keyLabels = getKeyValues();
49          for (KeyValue keyLabel : keyLabels) {
50          	optionValues.add(keyLabel.getKey());
51          }
52          return optionValues;
53      }
54  
55      /**
56       * @see KeyValuesFinder#getKeyLabelMap()
57       */
58      @Override
59  	public Map<String, String> getKeyLabelMap() {
60          Map<String, String> keyLabelMap = new HashMap<String, String>();
61  
62          List<KeyValue> keyLabels = getKeyValues();
63          for (KeyValue keyLabel : keyLabels) {
64          	keyLabelMap.put(keyLabel.getKey(), keyLabel.getValue());
65          }
66  
67          return keyLabelMap;
68      }
69  
70      /**
71       * @see KeyValuesFinder#getKeyLabel(String)
72       */
73      @Override
74  	public String getKeyLabel(String key) {
75          Map<String, String> keyLabelMap = getKeyLabelMap();
76  
77          if (keyLabelMap.containsKey(key)) {
78              return keyLabelMap.get(key);
79          }
80          return null;
81      }
82  
83      /**
84       * @see KeyValuesFinder#getKeyValues(boolean)
85       */
86      @Override
87  	public List<KeyValue> getKeyValues(boolean includeActiveOnly){
88      	return Collections.emptyList();
89      }
90  
91      /**
92       * @see org.kuali.rice.krad.keyvalues.KeyValuesFinder#clearInternalCache()
93       */
94  	@Override
95  	public void clearInternalCache() {
96  		// do nothing
97  	}
98  
99  }