Author: simonetripodi Date: Sat Apr 2 20:18:49 2011 New Revision: 1088105 URL: http://svn.apache.org/viewvc?rev=1088105&view=rev Log: Dictionary type can be statically types, no need to check value type at runtime
Modified: commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInDictionary.java Modified: commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInDictionary.java URL: http://svn.apache.org/viewvc/commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInDictionary.java?rev=1088105&r1=1088104&r2=1088105&view=diff ============================================================================== --- commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInDictionary.java (original) +++ commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/resource/names/DiscoverNamesInDictionary.java Sat Apr 2 20:18:49 2011 @@ -43,33 +43,33 @@ public class DiscoverNamesInDictionary log = _log; } - private Dictionary<String, Object> dictionary; + private Dictionary<String, String[]> dictionary; /** Construct a new resource discoverer */ public DiscoverNamesInDictionary() { - setDictionary(new Hashtable<String, Object>()); + setDictionary(new Hashtable<String, String[]>()); } /** Construct a new resource discoverer */ - public DiscoverNamesInDictionary(Dictionary<String, Object> dictionary) { + public DiscoverNamesInDictionary(Dictionary<String, String[]> dictionary) { setDictionary(dictionary); } - protected Dictionary<String, Object> getDictionary() { + protected Dictionary<String, String[]> getDictionary() { return dictionary; } /** * Specify set of class loaders to be used in searching. */ - public void setDictionary(Dictionary<String, Object> table) { + public void setDictionary(Dictionary<String, String[]> table) { this.dictionary = table; } public void addResource(String resourceName, String resource) { - dictionary.put(resourceName, resource); + addResource(resourceName, new String[]{ resource }); } public void addResource(String resourceName, String[] resources) { @@ -83,16 +83,7 @@ public class DiscoverNamesInDictionary if (log.isDebugEnabled()) log.debug("find: resourceName='" + resourceName + "'"); - Object baseResource = dictionary.get(resourceName); - - final String[] resources; - if (baseResource instanceof String) { - resources = new String[] { (String)baseResource }; - } else if (baseResource instanceof String[]) { - resources = (String[])baseResource; - } else { - resources = null; - } + final String[] resources = dictionary.get(resourceName); return new ResourceNameIterator() { private int idx = 0;