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 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 | |
|
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 | |
|
79 | 0 | } |
80 | |
} |
81 | |
} |