1 package net.sourceforge.pmd.util; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 11 public class TypeMap { 12 13 private Map typesByName; 14 15 19 public TypeMap(int initialSize) { 20 typesByName = new HashMap (initialSize); 21 } 22 23 28 public TypeMap(Class [] types) { 29 this(types.length); 30 add(types); 31 } 32 33 39 public void add(Class type) { 40 typesByName.put(type.getName(), type); 41 typesByName.put(ClassUtil.withoutPackageName(type.getName()), type); 42 } 43 44 50 public boolean contains(Class type) { 51 return typesByName.containsValue(type); 52 } 53 54 60 public boolean contains(String typeName) { 61 return typesByName.containsKey(typeName); 62 } 63 64 70 public Class typeFor(String typeName) { 71 return (Class )typesByName.get(typeName); 72 } 73 74 79 public void add(Class [] types) { 80 for (int i=0; i<types.length; i++) { 81 add(types[i]); 82 } 83 } 84 } 85 | Popular Tags |