| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AttributeSet |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * Copyright 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.kim.bo.types.dto; | |
| 17 | ||
| 18 | import java.util.HashMap; | |
| 19 | import java.util.Map; | |
| 20 | ||
| 21 | import org.apache.commons.lang.StringUtils; | |
| 22 | ||
| 23 | /** | |
| 24 | * Specialization of HashMap to facilitate web services and simplify API definitions. | |
| 25 | * | |
| 26 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 27 | * | |
| 28 | */ | |
| 29 | public class AttributeSet extends HashMap<String,String> { | |
| 30 | ||
| 31 | private static final long serialVersionUID = -5960854367616060667L; | |
| 32 | ||
| 33 | public AttributeSet() { | |
| 34 | 0 | super(); |
| 35 | 0 | } |
| 36 | ||
| 37 | /** | |
| 38 | * Create an AttributeSet with a single key/value pair. | |
| 39 | */ | |
| 40 | public AttributeSet( String key, String value ) { | |
| 41 | 0 | this(); |
| 42 | 0 | put( key, value ); |
| 43 | 0 | } |
| 44 | ||
| 45 | /** | |
| 46 | * @see HashMap#HashMap(int) | |
| 47 | * | |
| 48 | * @param initialSize | |
| 49 | */ | |
| 50 | public AttributeSet( int initialSize ) { | |
| 51 | 0 | super( initialSize ); |
| 52 | 0 | } |
| 53 | ||
| 54 | public AttributeSet( Map<String,String> map ) { | |
| 55 | 0 | super(); |
| 56 | 0 | if ( map != null ) { |
| 57 | 0 | putAll( map ); |
| 58 | } | |
| 59 | 0 | } |
| 60 | ||
| 61 | public String formattedDump( int indent ) { | |
| 62 | 0 | int maxKeyLen = 1; |
| 63 | 0 | for ( String key : this.keySet() ) { |
| 64 | 0 | if ( key!=null && key.length() > maxKeyLen ) { |
| 65 | 0 | maxKeyLen = key.length(); |
| 66 | } | |
| 67 | } | |
| 68 | 0 | StringBuffer sb = new StringBuffer(); |
| 69 | 0 | String indentStr = StringUtils.repeat( " ", indent ); |
| 70 | 0 | for ( String key : this.keySet() ) { |
| 71 | 0 | sb.append( indentStr ); |
| 72 | 0 | sb.append( StringUtils.rightPad( key, maxKeyLen, ' ' )); |
| 73 | 0 | sb.append( " --> " ); |
| 74 | 0 | sb.append( get( key ) ); |
| 75 | 0 | sb.append( '\n' ); |
| 76 | } | |
| 77 | 0 | return sb.toString(); |
| 78 | } | |
| 79 | } |