Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StringMap |
|
| 2.6;2.6 |
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.datadictionary.exporter; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.krad.exception.DuplicateKeyException; | |
20 | ||
21 | import java.util.LinkedHashMap; | |
22 | import java.util.Map; | |
23 | ||
24 | ||
25 | /** | |
26 | * Adds a litle strong type-checking and validation on top of the generic LinkedHashMap | |
27 | * | |
28 | * | |
29 | */ | |
30 | 0 | @Deprecated |
31 | 0 | public class StringMap extends LinkedHashMap<String, Object> { |
32 | private static final long serialVersionUID = 7364206011639131063L; | |
33 | ||
34 | /** | |
35 | * Associates the given String with the given Map value. | |
36 | * | |
37 | * @param key | |
38 | * @param value | |
39 | */ | |
40 | public void set(String key, Map<String, Object> value) { | |
41 | 0 | setUnique(key, value); |
42 | 0 | } |
43 | ||
44 | /** | |
45 | * Associates the given String with the given String value. | |
46 | * | |
47 | * @param key | |
48 | * @param value | |
49 | */ | |
50 | public void set(String key, String value) { | |
51 | 0 | setUnique(key, value); |
52 | 0 | } |
53 | ||
54 | ||
55 | /** | |
56 | * Verifies that the key isn't blank, and that the value isn't null, and prevents duplicate keys from being used. | |
57 | * | |
58 | * @param key | |
59 | * @param value | |
60 | */ | |
61 | private void setUnique(String key, Object value) { | |
62 | 0 | if (StringUtils.isBlank(key)) { |
63 | 0 | throw new IllegalArgumentException("invalid (blank) key"); |
64 | } | |
65 | 0 | if (value == null) { |
66 | 0 | throw new IllegalArgumentException("invalid (null) value"); |
67 | } | |
68 | ||
69 | 0 | if (containsKey(key)) { |
70 | 0 | throw new DuplicateKeyException("duplicate key '" + key + "'"); |
71 | } | |
72 | ||
73 | 0 | super.put(key, value); |
74 | 0 | } |
75 | ||
76 | @Override | |
77 | public Object put(String key, Object value) { | |
78 | 0 | throw new UnsupportedOperationException("direct calls to put not supported"); |
79 | } | |
80 | ||
81 | @Override | |
82 | public void putAll(Map<? extends String, ? extends Object> m) { | |
83 | 0 | throw new UnsupportedOperationException("direct calls to put not supported"); |
84 | } | |
85 | } |