1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.keyvalues;
17
18 import java.util.Collection;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.rice.core.api.util.ConcreteKeyValue;
23 import org.kuali.rice.core.api.util.KeyValue;
24
25 import com.google.common.base.Function;
26 import com.google.common.collect.Collections2;
27 import com.google.common.collect.ImmutableList;
28 import com.google.common.collect.ImmutableMap;
29
30
31 public final class KeyValuesFinderFactory {
32 private KeyValuesFinderFactory() {
33 throw new UnsupportedOperationException("do not call");
34 }
35
36 public static KeyValuesFinder fromMap(Map<String, String> map) {
37 if (map == null) {
38 throw new IllegalArgumentException("map is null");
39 }
40
41 return new MapBased(map);
42 }
43
44 private static final class MapBased implements KeyValuesFinder {
45 private final Map<String, String> map;
46
47 private MapBased(Map<String, String> map) {
48 this.map = ImmutableMap.copyOf(map);
49 }
50
51 @Override
52 public List<KeyValue> getKeyValues() {
53 Collection<KeyValue> kvs = Collections2.transform(map.entrySet(), new Function<Map.Entry<String, String>, KeyValue>() {
54 @Override
55 public KeyValue apply(Map.Entry<String, String> input) {
56 return new ConcreteKeyValue(input);
57 }
58 });
59 return ImmutableList.copyOf(kvs);
60 }
61
62 @Override
63 public List<KeyValue> getKeyValues(boolean includeActiveOnly) {
64 return getKeyValues();
65 }
66
67 @Override
68 public Map<String, String> getKeyLabelMap() {
69 return map;
70 }
71
72 @Override
73 public String getKeyLabel(String key) {
74 return map.get(key);
75 }
76
77 @Override
78 public void clearInternalCache() {
79
80 }
81 }
82 }