01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.lookup.keyvalues;
17:
18: import java.util.ArrayList;
19: import java.util.Collection;
20: import java.util.HashMap;
21: import java.util.Iterator;
22: import java.util.List;
23: import java.util.Map;
24:
25: import org.kuali.core.web.ui.KeyLabelPair;
26:
27: /**
28: * This class returns list of chart key value pairs.
29: *
30: *
31: */
32: public abstract class KeyValuesBase implements KeyValuesFinder {
33: public Collection getOptionLabels() {
34: List optionLabels = new ArrayList();
35:
36: List keyLabels = getKeyValues();
37: for (Iterator iter = keyLabels.iterator(); iter.hasNext();) {
38: KeyLabelPair keyLabel = (KeyLabelPair) iter.next();
39: optionLabels.add(keyLabel.getLabel());
40: }
41: return optionLabels;
42: }
43:
44: public Collection getOptionValues() {
45: List optionValues = new ArrayList();
46:
47: List keyLabels = getKeyValues();
48: for (Iterator iter = keyLabels.iterator(); iter.hasNext();) {
49: KeyLabelPair keyLabel = (KeyLabelPair) iter.next();
50: optionValues.add(keyLabel.getKey());
51: }
52: return optionValues;
53: }
54:
55: /**
56: * @see org.kuali.core.lookup.keyvalues.KeyValuesFinder#getKeyLabelMap()
57: */
58: public Map getKeyLabelMap() {
59: Map keyLabelMap = new HashMap();
60:
61: List keyLabels = getKeyValues();
62: for (Iterator iter = keyLabels.iterator(); iter.hasNext();) {
63: KeyLabelPair keyLabel = (KeyLabelPair) iter.next();
64: keyLabelMap.put(keyLabel.getKey(), keyLabel.getLabel());
65: }
66:
67: return keyLabelMap;
68: }
69:
70: /**
71: * @see org.kuali.core.lookup.keyvalues.KeyValuesFinder#getKeyLabel(java.lang.String)
72: */
73: public String getKeyLabel(String key) {
74: Map keyLabelMap = getKeyLabelMap();
75:
76: if (keyLabelMap.containsKey(key)) {
77: return (String) keyLabelMap.get(key);
78: } else {
79: return "";
80: }
81: }
82: }
|