001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.keyvalues; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Collections; 022import java.util.HashMap; 023import java.util.List; 024import java.util.Map; 025 026import org.kuali.rice.core.api.util.KeyValue; 027 028/** 029 * Abstract base implementation of {@link KeyValuesFinder} 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033public abstract class KeyValuesBase implements KeyValuesFinder, Serializable { 034 035 public Collection<String> getOptionLabels() { 036 Collection<String> optionLabels = new ArrayList<String>(); 037 038 Collection<KeyValue> keyLabels = getKeyValues(); 039 for (KeyValue keyLabel : keyLabels) { 040 optionLabels.add(keyLabel.getValue()); 041 } 042 return optionLabels; 043 } 044 045 public Collection<String> getOptionValues() { 046 Collection<String> optionValues = new ArrayList<String>(); 047 048 Collection<KeyValue> keyLabels = getKeyValues(); 049 for (KeyValue keyLabel : keyLabels) { 050 optionValues.add(keyLabel.getKey()); 051 } 052 return optionValues; 053 } 054 055 /** 056 * @see KeyValuesFinder#getKeyLabelMap() 057 */ 058 @Override 059 public Map<String, String> getKeyLabelMap() { 060 Map<String, String> keyLabelMap = new HashMap<String, String>(); 061 062 List<KeyValue> keyLabels = getKeyValues(); 063 for (KeyValue keyLabel : keyLabels) { 064 keyLabelMap.put(keyLabel.getKey(), keyLabel.getValue()); 065 } 066 067 return keyLabelMap; 068 } 069 070 /** 071 * @see KeyValuesFinder#getKeyLabel(String) 072 */ 073 @Override 074 public String getKeyLabel(String key) { 075 Map<String, String> keyLabelMap = getKeyLabelMap(); 076 077 if (keyLabelMap.containsKey(key)) { 078 return keyLabelMap.get(key); 079 } 080 return null; 081 } 082 083 /** 084 * @see KeyValuesFinder#getKeyValues(boolean) 085 */ 086 @Override 087 public List<KeyValue> getKeyValues(boolean includeActiveOnly){ 088 return Collections.emptyList(); 089 } 090 091 /** 092 * @see org.kuali.rice.krad.keyvalues.KeyValuesFinder#clearInternalCache() 093 */ 094 @Override 095 public void clearInternalCache() { 096 // do nothing 097 } 098 099}