001: package csdl.jblanket.util;
002:
003: import csdl.jblanket.modifier.MethodCollector;
004:
005: import java.io.File;
006: import java.util.HashMap;
007: import java.util.Map;
008: import java.util.Set;
009:
010: /**
011: * Provides an access point to all types of method categories. Implementation of this class
012: * follows the Singleton design pattern.
013: * <p>
014: * The following are supported method categories with default file names:
015: * <ul>
016: * <li> totalMethods
017: * <li> untestableMethods
018: * <li> excludedMethods
019: * <li> oneLineMethods
020: * <li> constructorMethods
021: * <li> excludedIndividualMethods
022: * <li> total.testedMethods
023: * <li> total.untestedMethods
024: * <li> testedMethods
025: * <li> untestedMethods
026: * </ul>
027: * <p>
028: * This class was implemented to simplify passing file names and associating them with the above
029: * mentioned method categories.
030: *
031: * @author Joy M. Agustin
032: * @version $Id: MethodCategories.java,v 1.1 2004/11/07 00:32:24 timshadel Exp $
033: */
034: public class MethodCategories {
035:
036: /** Instance of the MethodCategories class */
037: private static MethodCategories theInstance = null;
038: /** Container mapping category -> fileName */
039: private Map categories;
040: /** Output directory for JBlanket data */
041: private String jblanketDir;
042:
043: /** Initializes a new MethodCategories instance. */
044: private MethodCategories() {
045:
046: this .categories = new HashMap();
047: this .jblanketDir = MethodCollector.getJBlanketDir();
048: }
049:
050: /**
051: * Gets the current instance of MethodCategories
052: *
053: * @return the MehtodCategories instance.
054: */
055: public static MethodCategories getInstance() {
056:
057: if (MethodCategories.theInstance == null) {
058: MethodCategories.theInstance = new MethodCategories();
059: }
060:
061: return MethodCategories.theInstance;
062: }
063:
064: /**
065: * Adds a category and maps it to the default XML file name. If no default file name exists,
066: * then <code>null</code> is stored as the file name.
067: * <p>
068: * Example:
069: * <pre>
070: * category -> <jblanket.dir>/<default file name>
071: * </pre>
072: *
073: * @param category the method category.
074: */
075: public void addCategory(String category) {
076: this .addCategory(category, DefaultFileName
077: .getDefaultFileName(category));
078: }
079:
080: /**
081: * Adds a category and maps it to <code>fileName</code>.
082: * <p>
083: * Example:
084: * <pre>
085: * category -> <jblanket.dir>/<code>fileName</code>
086: * </pre>
087: *
088: * @param category the method category.
089: * @param fileName the name of the file where methods in <code>category</code> is stored.
090: */
091: public void addCategory(String category, String fileName) {
092:
093: if (fileName == null) {
094: this .categories.put(category, null);
095: } else {
096: this .categories.put(category, this .jblanketDir
097: + File.separator + fileName);
098: }
099: }
100:
101: /**
102: * Returns the fully qualified <code>fileName</code> associated with <code>category</code>.
103: *
104: * @param category the category to retrieve.
105: * @return the fully qualified <code>fileName</code> associated with <code>category</code>,
106: * or null if one doesn't exist.
107: */
108: public String getFileName(String category) {
109:
110: String fileName = (String) this .categories.get(category);
111: if (fileName == null) {
112: addCategory(category);
113: fileName = (String) this .categories.get(category);
114: }
115:
116: return fileName;
117: }
118:
119: /**
120: * Returns all the categories stored in this container.
121: *
122: * @return the categories stored in this container.
123: */
124: public Set getCategories() {
125: return this.categories.keySet();
126: }
127: }
|