Coverage Report - org.kuali.rice.krad.keyvalues.KeyValuesFinderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
KeyValuesFinderFactory
0%
0/5
0%
0/2
1.333
KeyValuesFinderFactory$1
N/A
N/A
1.333
KeyValuesFinderFactory$MapBased
0%
0/10
N/A
1.333
KeyValuesFinderFactory$MapBased$1
0%
0/2
N/A
1.333
 
 1  
 /**
 2  
  * Copyright 2005-2011 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 com.google.common.base.Function;
 19  
 import com.google.common.collect.Collections2;
 20  
 import com.google.common.collect.ImmutableList;
 21  
 import com.google.common.collect.ImmutableMap;
 22  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 23  
 import org.kuali.rice.core.api.util.KeyValue;
 24  
 
 25  
 import java.util.Collection;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 
 29  
 /** a factory for creating key-values finders. */
 30  
 public final class KeyValuesFinderFactory {
 31  0
     private KeyValuesFinderFactory() {
 32  0
         throw new UnsupportedOperationException("do not call");
 33  
     }
 34  
 
 35  
     public static KeyValuesFinder fromMap(Map<String, String> map) {
 36  0
         if (map == null) {
 37  0
             throw new IllegalArgumentException("map is null");
 38  
         }
 39  
 
 40  0
         return new MapBased(map);
 41  
     }
 42  
 
 43  0
     private static final class MapBased implements KeyValuesFinder {
 44  
         private final Map<String, String> map;
 45  
 
 46  0
         private MapBased(Map<String, String> map) {
 47  0
             this.map = ImmutableMap.copyOf(map);
 48  0
         }
 49  
 
 50  
         @Override
 51  
         public List<KeyValue> getKeyValues() {
 52  0
             Collection<KeyValue> kvs = Collections2.transform(map.entrySet(), new Function<Map.Entry<String, String>, KeyValue>() {
 53  
                 @Override
 54  
                 public KeyValue apply(Map.Entry<String, String> input) {
 55  0
                     return new ConcreteKeyValue(input);
 56  
                 }
 57  
             });
 58  0
             return ImmutableList.copyOf(kvs);
 59  
         }
 60  
 
 61  
         @Override
 62  
         public List<KeyValue> getKeyValues(boolean includeActiveOnly) {
 63  0
             return getKeyValues();
 64  
         }
 65  
 
 66  
         @Override
 67  
         public Map<String, String> getKeyLabelMap() {
 68  0
             return map;
 69  
         }
 70  
 
 71  
         @Override
 72  
         public String getKeyLabel(String key) {
 73  0
             return map.get(key);
 74  
         }
 75  
 
 76  
         @Override
 77  
         public void clearInternalCache() {
 78  
             //do nothing
 79  0
         }
 80  
     }
 81  
 }