1 54 55 package junitx.util; 56 57 import java.util.Hashtable ; 58 import java.util.Map ; 59 60 126 public class ResourceManager { 127 128 private static Map resources = new Hashtable (); 129 130 133 private ResourceManager() { 134 } 135 136 145 public static void addResource(String key, 146 Object value) 147 throws IllegalArgumentException { 148 if (resources.containsKey(key)) { 149 throw new IllegalArgumentException ("Resource with key '" + key + "' already exists"); 150 } 151 resources.put(key, value); 152 } 153 154 162 public static Object getResource(String key) 163 throws NullPointerException { 164 if (key == null) { 165 throw new NullPointerException ("Invalid key <null>"); 166 } 167 return resources.get(key); 168 } 169 170 174 public static boolean containsResource(String key) { 175 return resources.containsKey(key); 176 } 177 178 184 public static void removeResource(String key) { 185 resources.remove(key); 186 } 187 188 } 189 | Popular Tags |