1 package com.puppycrawl.tools.checkstyle; 20 21 import java.util.ArrayList ; 22 import java.util.Map ; 23 import java.util.HashMap ; 24 import java.util.Set ; 25 26 import com.puppycrawl.tools.checkstyle.api.CheckstyleException; 27 import com.puppycrawl.tools.checkstyle.api.Configuration; 28 29 33 public final class DefaultConfiguration implements Configuration 34 { 35 36 private final String mName; 37 38 39 private final ArrayList mChildren = new ArrayList (); 40 41 42 private final Map mAttributeMap = new HashMap (); 43 44 48 public DefaultConfiguration(String aName) 49 { 50 mName = aName; 51 } 52 53 54 public String [] getAttributeNames() 55 { 56 final Set keySet = mAttributeMap.keySet(); 57 return (String []) keySet.toArray(new String [keySet.size()]); 58 } 59 60 61 public String getAttribute(String aName) throws CheckstyleException 62 { 63 if (!mAttributeMap.containsKey(aName)) { 64 throw new CheckstyleException( 66 "missing key '" + aName + "' in " + getName()); 67 } 68 return (String ) mAttributeMap.get(aName); 69 } 70 71 72 public Configuration[] getChildren() 73 { 74 return (Configuration[]) mChildren.toArray( 75 new Configuration[mChildren.size()]); 76 } 77 78 79 public String getName() 80 { 81 return mName; 82 } 83 84 88 public void addChild(Configuration aConfiguration) 89 { 90 mChildren.add(aConfiguration); 91 } 92 93 97 public void removeChild(final Configuration aConfiguration) 98 { 99 mChildren.remove(aConfiguration); 100 } 101 102 107 public void addAttribute(String aName, String aValue) 108 { 109 mAttributeMap.put(aName, aValue); 110 } 111 112 } 113 | Popular Tags |