Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 84   Methods: 7
NCLOC: 31   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TypeMap.java 100% 100% 100% 100%
coverage
 1    package net.sourceforge.pmd.util;
 2   
 3    import java.util.HashMap;
 4    import java.util.Map;
 5   
 6    /**
 7    * A specialized map that stores classes by both their full and short names.
 8    *
 9    * @author Brian Remedios
 10    */
 11    public class TypeMap {
 12   
 13    private Map typesByName;
 14   
 15    /**
 16    * Constructor for TypeMap.
 17    * @param initialSize int
 18    */
 19  932 public TypeMap(int initialSize) {
 20  932 typesByName = new HashMap(initialSize);
 21    }
 22   
 23    /**
 24    * Constructor for TypeMap that takes in an initial set of types.
 25    *
 26    * @param types Class[]
 27    */
 28  932 public TypeMap(Class[] types) {
 29  932 this(types.length);
 30  932 add(types);
 31    }
 32   
 33    /**
 34    * Adds a type to the receiver and stores it keyed by both its full
 35    * and short names.
 36    *
 37    * @param type Class
 38    */
 39  7456 public void add(Class type) {
 40  7456 typesByName.put(type.getName(), type);
 41  7456 typesByName.put(ClassUtil.withoutPackageName(type.getName()), type);
 42    }
 43   
 44    /**
 45    * Returns whether the type is known to the receiver.
 46    *
 47    * @param type Class
 48    * @return boolean
 49    */
 50  21 public boolean contains(Class type) {
 51  21 return typesByName.containsValue(type);
 52    }
 53   
 54    /**
 55    * Returns whether the typeName is known to the receiver.
 56    *
 57    * @param typeName String
 58    * @return boolean
 59    */
 60  41 public boolean contains(String typeName) {
 61  41 return typesByName.containsKey(typeName);
 62    }
 63   
 64    /**
 65    * Returns the type for the typeName specified.
 66    *
 67    * @param typeName String
 68    * @return Class
 69    */
 70  22 public Class typeFor(String typeName) {
 71  22 return (Class)typesByName.get(typeName);
 72    }
 73   
 74    /**
 75    * Adds an array of types to the receiver at once.
 76    *
 77    * @param types Class[]
 78    */
 79  932 public void add(Class[] types) {
 80  932 for (int i=0; i<types.length; i++) {
 81  7456 add(types[i]);
 82    }
 83    }
 84    }