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